We are currently in the process of upgrading our rails version and I have come across some weird error in one of my date_select tags.
Here is the culprit:
<%= date_select :consultant_assignment, :start_date, :order => [:day, :month, :year],
:start_year => 5.years.ago.year, :end_year => 5.years.from_now.year, :use_short_month => true %>
This throws out an error like this:
NoMethodError
in Profiles#show
Showing app/views/people/_upcoming_assignments.html.erb where line #46 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.size
Extracted source (around line #46):
43: <label for="consultant_assignment_start_date"><%= _('Start') %>:</label>
44: <% debugger %>
45:
46: <%= date_select :consultant_assignment, :start_date, :order => [:day, :month, :year], :start_year => 5.years.ago.year, :end_year => 5.years.from_now.year, :use_short_month => true %>
47:
48:
49:
I have tried to trace this problem and it seems that the error is generated when I put in the :month option in the :order array. So when I do :order => [:day, :year] the page loads perfectly.
I have searched for the exact problem but being more of a front end deisgner, I'm not sure how to procede with this. Is this an error by my code? Or is it a deprecated method?
Here is the application trace
:
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:746:in `_unmemoized_month_names'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/memoizable.rb:72:in `month_names'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:781:in `month_name'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:708:in `select_month'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:705:in `upto'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:705:in `select_month'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:898:in `send'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:898:in `build_selects_from_types'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:896:in `each'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:896:in `build_selects_from_types'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:646:in `select_date'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:920:in `to_date_select_tag_without_error_wrapping'
I have googled about unmemoized month names but I found nada.
Okay, I've tried taking out the whole :order clause just to make the darn thing work. This time it doesn't throw an error but the tag doesn't appear! I tried checking in irb and apparently my date_select tag is not returning any select tags, but just a bunch of hidden tags!
I tried this with the default rails example:
date_select("post", "written_on")
irb returns this:
=> "\n\n\n"
as you can see, no select tag anywhere. I tried datetime_select and I see a select tag in there. So what's the deal with 2.3.8's date_select?