# Writing multiple checkbox values

**URL:** <https://www.ruby-forum.com/t/writing-multiple-checkbox-values/142973>\
**Category:** Rails\
**Created:** [July 14, 2008, 4:32am UTC](https://www.ruby-forum.com/t/writing-multiple-checkbox-values/142973 "2008-07-14T04:32:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonwold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e36b37/32.png) [@jasonwold](https://www.ruby-forum.com/u/jasonwold)\
**Post date:** [July 14, 2008, 4:32am UTC](https://www.ruby-forum.com/t/writing-multiple-checkbox-values/142973/1 "2008-07-14T04:32:49Z")

</div>

Is it possible to write multiple checkbox values? When i click on  
submit, the first value “accounting\_services” is written to the  
database, but all of the others are ignored.  
I created a column in my registration database table with a title of  
organizationservices, and type of string.

\<%= f.check\_box(:organizationservices, {:class =\> 'check\_box'},"accounting\_services","") %\>Accounting/Auditing Services \<%= f.check\_box(:organizationservices, {:class =\> 'check\_box'},"Actuarial\_Services","") %\>Actuarial Services \<%= f.check\_box(:organizationservices, {:class =\> 'check\_box'},"com\_dev","") %\>Alternative/Comm. Dev. Investments \<%= f.check\_box(:organizationservices, {:class =\> 'check\_box'},"test 1","not test 1") %\>Test

thank you,  
Jason

---

<div class="post-metadata">

**Author:** ![jasonwold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e36b37/32.png) [@jasonwold](https://www.ruby-forum.com/u/jasonwold)\
**Post date:** [July 14, 2008, 10:52am UTC](https://www.ruby-forum.com/t/writing-multiple-checkbox-values/142973/2 "2008-07-14T10:52:35Z")

</div>

There is a browser limitation on checkboxes.  
At least for some browsers, the checkbox value is only sent,  
if the checkbox is checked. for unchecked boxes nothing is  
returned.  
So you must check against params[:model\_name][:checkbox\_name].nil?  
or something like that.

---

<div class="post-metadata">

**Author:** ![jasonwold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e36b37/32.png) [@jasonwold](https://www.ruby-forum.com/u/jasonwold)\
**Post date:** [July 14, 2008, 11:02am UTC](https://www.ruby-forum.com/t/writing-multiple-checkbox-values/142973/3 "2008-07-14T11:02:23Z")

</div>

Jason White wrote:

> Is it possible to write multiple checkbox values? When i click on  
> submit, the first value “accounting\_services” is written to the  
> database, but all of the others are ignored.  
> I created a column in my registration database table with a title of  
> organizationservices, and type of string.
> 
> \<%= f.check\_box(:organizationservices, {:class =\> 'check\_box'},"accounting\_services","") %\>Accounting/Auditing Services \<%= f.check\_box(:organizationservices, {:class =\> 'check\_box'},"Actuarial\_Services","") %\>Actuarial Services \<%= f.check\_box(:organizationservices, {:class =\> 'check\_box'},"com\_dev","") %\>Alternative/Comm. Dev. Investments \<%= f.check\_box(:organizationservices, {:class =\> 'check\_box'},"test 1","not test 1") %\>Test
> 
> thank you,  
> Jason

Hi there,  
so,  
the html you want to generate is;

this will create an array in the params

:organisation =\> {:organisationservices =\> [“abc”]}

with all the checked values being put in there.

but, I dont think you can do this with the :form\_for syntax.

so, instead

 \<%= check\_box\_tag("organisation[organisationservices][]", "accounting\_services", @organisation.accounting\_services.include?("accounting\_services")) %\>Accounting/Auditing Services 

…

I suggest you wrap this into a helper if you need to use it a lot…

Matthew R.  
[http://www.workingwithrails.com/person/12394-matthew-rudy-jacobs](http://www.workingwithrails.com/person/12394-matthew-rudy-jacobs)
