Reputation: 473
I'm attempting to write a RoR controller that will post data to a page on behalf of a preexisting form. This form consists of a long list of checkboxes.
I use a hash that represents the name => value pairs of the form elements. The problem is that all the checkboxes in the form use the same name but different value. I do not know how to represent multiple values for the same name in my form hash.
So as it stands I can only emulate having a single checkbox selected.
How can I represent multiple checkboxes being checked in my form hash for my RoR controller?
Upvotes: 1
Views: 2191
Reputation: 3780
This will pass all the checked values as an array.
<input type="checkbox" name="theName[]"/>
<input type="checkbox" name="theName[]"/>
Upvotes: 3
Reputation: 2606
It comes through as an array in that case: so the params would include something like {:user => {:activity => ['hiking', 'boating', 'swimming']}}
Check out: http://www.skuunk.com/2008/05/checkbox-arrays-in-rails.html
Upvotes: 1