views:

28

answers:

2

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?

A: 

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

njorden
I tried doing something like "checkboxname"=>["value1","value2"] in the hash, but it seemed to post it as "value1value2".
bsirang
A: 

This will pass all the checked values as an array.

<input type="checkbox" name="theName[]"/>
<input type="checkbox" name="theName[]"/>
I can't modify the form. I'm writing a controller to mimic a preexisting form by posting the same values in an attempt to perform a task more efficiently.
bsirang