# List of Checkboxes

**URL:** <https://www.ruby-forum.com/t/list-of-checkboxes/83876>\
**Category:** Rails\
**Created:** [January 30, 2007, 12:24pm UTC](https://www.ruby-forum.com/t/list-of-checkboxes/83876 "2007-01-30T12:24:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![laurin1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/919ad9/32.png) [@laurin1](https://www.ruby-forum.com/u/laurin1)\
**Post date:** [January 30, 2007, 12:24pm UTC](https://www.ruby-forum.com/t/list-of-checkboxes/83876/1 "2007-01-30T12:24:53Z")

</div>

Hi,

Does anyone have a link or information on how to handle lists of  
checkboxes  
in rails?

I am working on a property site and each property has a list of features  
which are rendered as  
a list of checkboxes. I am trying to figure out how to handle which ones  
are  
checked and which not  
and persist them back to the database.

Sorry for the noob question.

Keith

---

<div class="post-metadata">

**Author:** ![laurin1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/919ad9/32.png) [@laurin1](https://www.ruby-forum.com/u/laurin1)\
**Post date:** [January 30, 2007, 12:43pm UTC](https://www.ruby-forum.com/t/list-of-checkboxes/83876/2 "2007-01-30T12:43:22Z")

</div>

The check\_box helper in your view and a call to update\_attributes in  
your controller are all you need 🙂

---

<div class="post-metadata">

**Author:** ![laurin1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/919ad9/32.png) [@laurin1](https://www.ruby-forum.com/u/laurin1)\
**Post date:** [January 30, 2007, 12:49pm UTC](https://www.ruby-forum.com/t/list-of-checkboxes/83876/3 "2007-01-30T12:49:58Z")

</div>

Cool, Didn’t know there was a checkbox helper.

Thanks for the answer.

Keith

---

<div class="post-metadata">

**Author:** ![laurin1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/919ad9/32.png) [@laurin1](https://www.ruby-forum.com/u/laurin1)\
**Post date:** [January 31, 2007, 1:05pm UTC](https://www.ruby-forum.com/t/list-of-checkboxes/83876/4 "2007-01-31T13:05:09Z")

</div>

Hi!

On Jan 30, 2007, at 14:43, Mick S. wrote:

> The check\_box helper in your view and a call to update\_attributes in  
> your controller are all you need 🙂

Could you please give me the example of using the checkbox helper?

I need to show a list of tags so that tags belonging to the page are  
checked. I’m bewildered with “method” parameter — it should be a string  
and I don’t know how to write it if I want to call  
@page.includes?(topic).

Your sincerely,  
Damian/Three-eyed Fish

---

<div class="post-metadata">

**Author:** ![laurin1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/919ad9/32.png) [@laurin1](https://www.ruby-forum.com/u/laurin1)\
**Post date:** [January 31, 2007, 2:31pm UTC](https://www.ruby-forum.com/t/list-of-checkboxes/83876/5 "2007-01-31T14:31:18Z")

</div>

hi damian  
i recently did a similar thing, so here’s maybe what you are looking  
for - it may not be the best or most elegant way - i didn’t use  
checkbox helper, because i couldn’t get it going properly - i’m still  
a newbie, but this works

in your view:  
\<% for section in @sections%\>

\<input type=“checkbox” id= “\<%section.id%\>” name=“section\_ids[]”  
value="\<%=section.id%\>"  
\<%if @content.sections.include? section %\>  
checked=“checked”  
\<%end%\>

> 

\<%=section.name%\>

\<% end%\>

in controller (new or create):  
@content.sections= Section.find(@params[:section\_ids]) if  
@params[:section\_ids]

hope this helps

george

---

<div class="post-metadata">

**Author:** ![laurin1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/919ad9/32.png) [@laurin1](https://www.ruby-forum.com/u/laurin1)\
**Post date:** [January 31, 2007, 3:26pm UTC](https://www.ruby-forum.com/t/list-of-checkboxes/83876/6 "2007-01-31T15:26:24Z")

</div>

On Tuesday 30 January 2007 12:24, Keith D. wrote:

> Does anyone have a link or information on how to handle lists of  
> checkboxes in rails?

Try this plugin

[http://www.agilewebdevelopment.com/plugins/multiple\_select\_helper](http://www.agilewebdevelopment.com/plugins/multiple_select_helper)

HTH,  
Michael

–  
Michael S.  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.schuerig.de/michael/](http://www.schuerig.de/michael/)

---

<div class="post-metadata">

**Author:** ![laurin1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/919ad9/32.png) [@laurin1](https://www.ruby-forum.com/u/laurin1)\
**Post date:** [January 31, 2007, 4:11pm UTC](https://www.ruby-forum.com/t/list-of-checkboxes/83876/7 "2007-01-31T16:11:29Z")

</div>

Thanks Michael,

Just tried it out and it does exactly what I was looking for and in good  
rails  
style it took about 5 minutes as well.

Keith

---

<div class="post-metadata">

**Author:** ![laurin1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/919ad9/32.png) [@laurin1](https://www.ruby-forum.com/u/laurin1)\
**Post date:** [January 31, 2007, 2:35pm UTC](https://www.ruby-forum.com/t/list-of-checkboxes/83876/8 "2007-01-31T14:35:17Z")

</div>

I just tend to use:

\<%= check\_box(“product”, “is\_active”) %\>

where “product” is an AR object stored in @product, and “is\_active” is a  
column name of type boolean (if the method is a string, it is taken to  
be an AR column name).

Further information can be found in the Rails wiki:

[http://wiki.rubyonrails.org/rails/pages/HowToUseCheckBoxes](http://wiki.rubyonrails.org/rails/pages/HowToUseCheckBoxes)

---

<div class="post-metadata">

**Author:** ![laurin1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/919ad9/32.png) [@laurin1](https://www.ruby-forum.com/u/laurin1)\
**Post date:** [February 1, 2007, 7:37am UTC](https://www.ruby-forum.com/t/list-of-checkboxes/83876/9 "2007-02-01T07:37:42Z")

</div>

On Jan 31, 2007, at 16:30, mr\_robot wrote:

> \<input type=“checkbox” id= “\<%section.id%\>” name=“section\_ids[]”  
> in controller (new or create):  
> @content.sections= Section.find(@params[:section\_ids]) if  
> @params[:section\_ids]
> 
> hope this helps
> 
> george

Thank you very much!  
This is an approach I’m using now, I just wanted to see whether I can  
write less code. I’m thinking of writing my own helper for it, but as  
I’m a newbie, I should find out how to do it.

Yours sincerely,  
Damian/Three-eyed Fish
