Hi, I have a check box in a non - model based form and when I submit the form with ''Un Checked'' check box the params hash doesn''t contain the check box. Whenever I submit the form with the check box ''Checked'', I see the same coming through params hash in my controller. Since I dynamically generate the form element (Here, check box), if I don''t get anything in the params, there is no way of telling if the check box is ''unchecked'' or there is no check box in the form. Can someone help me understand what I am missing here and how to force Rails to include all the form elements in the params hash irrespective of the user action? I tried asking many people and no one seems to know the answer. Any help is highly appreciated. Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Mar-19 16:59 UTC
Re: form_tag params hash doesn''t contain form data
On Mar 19, 4:35 pm, RailSoft <ganesh.k...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have a check box in a non - model based form and when I submit > the form with ''Un Checked'' check box the params hash doesn''t contain > the check box. Whenever I submit the form with the check box > ''Checked'', I see the same coming through params hash in my controller. > Since I dynamically generate the form element (Here, check box), if I > don''t get anything in the params, there is no way of telling if the > check box is ''unchecked'' or there is no check box in the form. Can > someone help me understand what I am missing here and how to force > Rails to include all the form elements in the params hash irrespective > of the user action? I tried asking many people and no one seems to > know the answer. Any help is highly appreciated. >This isn''t a rails thing - the html standard dictates that unchecked check boxes submit no value. The rails check_box (but not check_box_tag ) helper makes this a little friendlier by actually generating two input fields: a check box and a hidden field: if the check box is ticked then rails ignores the hidden input (because it has the same name and comes afterwards) if it isn''t then only the hidden field is checked. Fred> Thanks.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---