This project is archived and is in readonly mode.
Multiparameter attributes should be set to nil when positional parameters are missing
-
grant
+1 for fixing this. The current behaviour makes for confusing errors. If a user enters 12 for the day, October for the month, and leaves the year empty, they'll get a validation error. If they instead enter 13 for the day, they'll get a 500 because MultiparameterAssignmentErrors was raised.
I like your patch but it doesn't cover the case of the smallest part of the multiparameter being empty. If a user leaves the day unselected, it will get switched to '1'. To be this fair, this seems to be the expected behaviour in Rails -- in that it's included in a couple of tests -- but I don't know why. Setting parts automatically makes sense if you are hiding them (say, showing only the month and year) but not otherwise. If a user hasn't selected a value, it shouldn't suddenly change on them.
Related is this rails-core discussion of empty string coercion: http://groups.google.com/group/r...
The multiparameter code was coercing the empty string to 0 by calling to_i on everything.
I don't think I've included a full fix. The date selects should be kept at their user-set values across requests, even if it doesn't form a valid date. I started poking at date_or_time_select and backed off... not enough time!
-
Pratik
- Assigned user set to Michael Koziarski
-
Brennan Dunn
+1 for this. Had the same issue happen recently.
-
Michael Koziarski
- Milestone changed from 2.x to 2.3.4
-
Chris Hapgood
+1 for fixing this. The behavior of date_select currently defies expectations.
-
sob
+1 for having this fixed. specific example of where this is useful: the rails documentation for date_select mentions a use case of having a users birthday but dropping the year (an hr requirement for some companies). I was overriding the year value to always use the current year to store the date but hiding the year prevents the date from ever being set to nil, say if the user wants to remove their birthday from their profile.
-
Rizwan Reza
- Tag changed from 2.1, activerecord, bug, edge, multiparameter, patch to 2.1, activerecord, bug, bugmash, edge, multiparameter, patch
-
Aditya Sanghi
- State changed from new to duplicate
Please see ticket 4346 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 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.
