I've run across this before, even in plain Rails. However, the last
time I looked at this date_select was still generating the old-style
1i,2i,3i fields instead of the current behavior.
Oddly enough, datetime fields don't have this problem - trying to put
a date of "February 31" into a datetime field just gets me back March
3...
--Matt Jones
--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
> I had been using the datepicker, but had to drop it because the format
> order wasn't always being picked up properly. once i get the agility/
> selenium setup running i will try to replicate that...
>
> meantime, i guess this *is* a bug? if it's a problem in rails/
> validates_timeliness, it's even more surprising...
Looks like we either need to borrow the Rails fallback code for this,
or figure out how to get out the attribute parsing business entirely.
Here's how Rails avoids the error:
begin
values = values_with_empty_parameters.collect do |
v| v.nil? ? 1 : v end
Date.new(*values)
rescue ArgumentError => ex # if Date.new raises an
exception on an invalid date
instantiate_time_object(name, values).to_date # we
instantiate Time object and convert it back to a date thus using
Time's logic in handling invalid dates
end
I was kind of disappointed when I found this; I was hoping there was a
slightly more glamorous solution than just swallowing the exception
and punting. Apparently not. :)
Tom, Bryan - do either of you recall why we're manually parsing those
attributes in convert_type_for_mass_assignment? Is it still needed in
2.3?
--Matt Jones
> Thanks. The thread wasn't very helpful and the code crashed on initialization, but I get the idea and I may try to fix this later. Perhaps someone should submit the issue to the hobo developers?
Oh, we know. :)
For 1.3, the resolution is likely to be only partial - I think it should be practical to at least get the thing to not blow up. Invalid dates will likely turn to blanks, though.
Post-1.3, I suspect the solution will be to get out of the multiparameter-parsing business entirely; Rails does it better internally, it'd be more compatible with other plugins, etc.
--Matt Jones
--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
> You could check this thread https://groups.google.com/forum/#!msg/hobousers/ofT7uwObOHc/ja1c2A809eEJ
>
> Or you could rewrite convert_type_for_mass_assignment to handle invalid dates. (Put something like the attachment in ..\config\initializers)
>
Code similar to this is now in the rails3 branch. The one gotcha is that it now handles invalid dates by converting them to equivalent valid dates - thus, setting a field to February 31 will actually result in March 3 being stored. This is identical to the behavior of the default Rails helpers, and is at least less user-hostile than blowing up with a 500 page.
--Matt Jones