Forum: Ruby on Rails date_select and impossible dates....

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
olivier Hericord (Guest)
on 2005-12-18 20:35
(Received via mailing list)
hi,

using date_select right from a generated scaffold code leads to an
error if an impossible date is selected (like the 31 of february)

can't get a way to correct this via a validation....
in fact that make sens because in the model i have the 'dateofbirth'
object which is a date object....

so providing an impossible day-month-year trio leads to an impossible
creation of the date object...


anyone with a solution?


thanks
Ken B. (Guest)
on 2005-12-18 22:02
(Received via mailing list)
I solved this problem by catching the error and displaying it to the
user.
Something similar to the following (off the top of my head, not really
looking at code at the moment):

begin
   if mymodel.save
     # everything ok
     ....
   else
    flash[:warning] = "error saving object"
   end
rescue => e
   flash[:warning] = e
end
render :action=>'new' and return if flash[:warning]
redirect_to :action=>'show', :id=>mymodel.id
This topic is locked and can not be replied to.