Question

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...

Was it helpful?

Solution

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 .

OTHER TIPS

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

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.

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top