Hi, I''m writing a form where the user should enter their date of birth. Here''s the code: <% form_for :applicant, :url=> {:action => "index"} do |f| %> ... <%= f.label :dob, "Date of Birth" %> <%= f.date_select :dob, :include_blank => true %> .. <p><%= submit_tag "Submit" %></p> <% end %> When I open the form in my browser everything is fine. However when I select "February" as the month, "31" as the day, don''t select a year, and then press "Submit" I get the following error message: 1 error(s) on assignment of multiparameter attributes Can anyone tell me why this is happening and how to avoid this? Thanks in advance. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 3 Apr 2009, at 13:38, Jim Burgess wrote:> > Hi, > > I''m writing a form where the user should enter their date of birth. > > Here''s the code: > > <% form_for :applicant, :url=> {:action => "index"} do |f| %> > ... > <%= f.label :dob, "Date of Birth" %> > <%= f.date_select :dob, :include_blank => true %> > .. > <p><%= submit_tag "Submit" %></p> > <% end %> > > When I open the form in my browser everything is fine. > However when I select "February" as the month, "31" as the day, don''t > select a year, and then press "Submit" I get the following error > message: > > 1 error(s) on assignment of multiparameter attributes > > Can anyone tell me why this is happening and how to avoid this?because rails is just faithfully passing this down and trying to create a date object for 31st february. update_attributes, Applicant.new etc. will raise ActiveRecord::MultiparameterAssignmentErrors when this happens. Fred> > Thanks in advance. > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the quick reply. It is important for my form that the date_select helper is not initialized with a value (ie. :include_blank => true). So, how could I stop the above error from happening? Could you give me a hint as to which direction to be thinking in? I''m still relatively new to Rails, so I would be grateful if any explination isn''t too complicated. Thanks once again. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 3 Apr 2009, at 14:02, Jim Burgess wrote:> > Thanks for the quick reply. > It is important for my form that the date_select helper is not > initialized with a value (ie. :include_blank => true). > So, how could I stop the above error from happening?You can''t easily stop the user entering dates like that with rails built in date helpers, so you need to rescue those exceptions and massage them into a friendly message. Fred> > Could you give me a hint as to which direction to be thinking in? > I''m still relatively new to Rails, so I would be grateful if any > explination isn''t too complicated. > Thanks once again. > > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> You can''t easily stop the user entering dates like that with rails > built in date helpers, so you need to rescue those exceptions and > massage them into a friendly message.Hi Fred, I''m quite surprised, as I would have thought that this makes the entire date_select helper open to misuse. Nonetheless, two further questions: How does one rescue exceptons in rails? I just need a point to start. Would it be a feasible option to use three text fields in the form that are unrelated to the model. Then in the controller string them together and make a date object? (that would be more or less how I would do it in PHP). -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 3, 4:29 pm, Jim Burgess <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > You can''t easily stop the user entering dates like that with rails > > built in date helpers, so you need to rescue those exceptions and > > massage them into a friendly message. > > Hi Fred, > I''m quite surprised, as I would have thought that this makes the entire > date_select helper open to misuse.date_select is simple & stupid. Seems to me like the worst case is someone enters an invalid date and the create fails.> Nonetheless, two further questions: > > How does one rescue exceptons in rails? I just need a point to start. >http://www.rubycentral.com/pickaxe/tut_exceptions.html> Would it be a feasible option to use three text fields in the form that > are unrelated to the model. Then in the controller string them together > and make a date object? (that would be more or less how I would do it in > PHP).You could. You''d still have to rescue the exception that is raised by Date::civil when you pass it 2009,2,29 (or do all the bounds checking yourself) Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Just thought I''d let you know how things turned out. I have discarded the idea of using date_select as it is full of inconsistencies which in the worst case can cause the application to crash. Instead I created three seperate text fields (DD-MM-YYYY)and using virtual attributes in the model mapped them to the "dob" field in the db. Now everything works like it should do (at last). I am surprised that this has presented me with such a problem as entering one''s dob into a form is a very common occurence. Nonetheless thanks for your help Fred. You definitely pointed me in the right direction. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---