Forum: Ruby on Rails form_tag params hash doesn't contain form data

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.
48a67b853cd51b9f923b2bace5d7f0dd?d=identicon&s=25 RailSoft (Guest)
on 2009-03-19 17:58
(Received via mailing list)
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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-19 18:01
(Received via mailing list)
On Mar 19, 4:35 pm, RailSoft <ganesh.k...@gmail.com> wrote:
> 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
This topic is locked and can not be replied to.