views:

153

answers:

4

I've set up my app exactly in line with the Railscasts Time Zone Episode 1 but when I run

<%= f.time_zone_select :time_zone, ActiveSupport::TimeZone.us_zones %>

I get this error

NoMethodError in Users#new

Showing app/views/users/new.html.erb where line #27 raised:

You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.<=>

With line 27 being the aforementioned line. I am really stuck on this...

A: 

Do you have a database field for that model named time_zone? is it named timezone instead?

You'd need a migration with something like:

add_column :users, :time_zone, :string

then

rake db:migrate
Steven Soroka
Yep they're already there and populated with seed data.
Jack
Anything else it could be? I've tried everything
Jack
I ran in to a problem here because of a spelling mistake between the database/migration and the view, so check for typos, if that wasn't obvious.Can you include a stack trace?
Steven Soroka
A: 

I have exactly the same problem. It seems to be related to Rails 2.3.8, because if I revert back to my previous version (2.3.4, by setting this in the /config/environment.rb), everything works fine. Looks like a bug. I'm checking out whether this bug report and resulting patch will solve this issue: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4942-activesupporttimezone-incorrectly-stores-bogus-values-in-zones_map#ticket-4942 .

Pascal Lindelauf
I do actually think this is a bug as well. I really can't even remember what I did to fix this but I eventually did. I was working with a locally seeded database so I ended up dropping, creating, and migrating it. I'm not sure if that's what it was, but it's worth a try if you can afford to do so.
Jack
A: 

Yes, this is a bug in 2.3.8, and it's been fixed in the aforementioned ticket.

It was probably caused by a stored time zone in a database field that didn't correspond to any time zone either Rails or TZInfo knew about. In our case, it was tripped by accidentally HTML encoding ampersands, so that Pacific Time (US & Canada) became Pacific Time (US &amp; Canada). http://github.com/rails/rails/commit/78e4d88c7071c633ee1eb68f49b90719aa198eaa should resolve it, but you might want to go back and make sure you don't still have any bad data in your DB.

texel
A: 

I had this same problem, which caused one of my Cucumber tests to fail. I upgraded to Rails 2.3.9 (from 2.3.8) and all tests passed. Good luck!

Peter Bloom