This project is archived and is in readonly mode.
Weird years list when year not selected
-
Chandra Sekar
- Tag changed from :prompttrue, date_select, year to date_select, year
-
Sam Oliver
This is happening because a ruby Date object is being happily created with a missing attribute.
For example:
User.new("date_of_birth(1i)"=>"", "date_of_birth(2i)"=>"12", "date_of_birth(3i)"=>"6")Will set date_of_birth to
0012-06-01Additionally, if the day is greater than 12,
ActiveRecord::MultiparameterAssignmentErrorsis raised (because day becomes month)Ideally the date would fail validates_presence_of if any of the attributes are missing. See the comments on a similar issue in http://dev.rubyonrails.org/ticke...
This also affects the :include_blank option for the same reason
-
Sam Oliver
- Tag changed from date_select, year to date_select, patch, year
This patch includes tests that demonstrate this incorrect month assignment bug and some extra tests for missing attributes with datetimes in multiparameter attributes.
I also noticed that creating/updating a 'date' column type with multiparameter attributes sets an empty year to 0001, whereas when with a 'datetime' column type, empty years are set to 2001. I'm not sure either of these defaults are ideal, but at least 2001 is less obviously wrong for many use cases. In either case it would make sense to have them consistent.
To clean this up, the patch converts all dates to Times and back again. This means the default year for a date set via multiparameter attributes will change from 0001 to 2001 and will be handled in the same way as 'datetime' columns.
With regard to Chandra's specific problem, this won't totally solve it (by default 2001 would be the center year instead of 1 though). But adding :start_year and :end_year should get around that.
-
Sam Oliver
- Importance changed from to
I think this was fixed in #1715 AR:Base mangles dates when user submits only part of the fields
-
Aditya Sanghi
- State changed from new to duplicate
Please see ticket #4346 time_select not interpreting the multi-parameter correctly where we're still discussing this issue after 2 years. We've provided a patch with many more tests and comprehensively covers date/time/datetime issues as well as blank and nil positional parameters among other issues.
Marking this as duplicate. Please provide your comments and review on #4346 time_select not interpreting the multi-parameter correctly.
