# Checkbox instead of dropdown

**URL:** <https://rubytalk.org/t/checkbox-instead-of-dropdown/41139>\
**Category:** ruby-talk\
**Created:** [3 October 2007 17:09 UTC](https://rubytalk.org/t/checkbox-instead-of-dropdown/41139 "2007-10-03T17:09:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Remco\_Swoany](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@Remco\_Swoany](https://rubytalk.org/u/Remco_Swoany)\
**Post date:** [3 October 2007 17:09 UTC](https://rubytalk.org/t/checkbox-instead-of-dropdown/41139/1 "2007-10-03T17:09:24Z")

</div>

Hi,

I am a RoR newby. The code below shows the categorie names, in a  
dropdown from the categories table and that works fine. But now i want  
to show the categories through checkboxen. How can i realise that??

\<select name="recipe[categorie\_id]"\>  
&nbsp;&nbsp;&nbsp;\<% @categories.each do |categorie| %\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<option value="\<%= [categorie.id](http://categorie.id) %\>"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= 'selected' if [categorie.id](http://categorie.id) == @recipe.categorie\_id %\>\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= [categorie.name](http://categorie.name) %\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</option\>  
&nbsp;&nbsp;&nbsp;\<% end %\>  
&nbsp;&nbsp;\</select\>

Grtz..remco

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![James\_Britt](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@James\_Britt](https://rubytalk.org/u/James_Britt)\
**Post date:** [3 October 2007 18:07 UTC](https://rubytalk.org/t/checkbox-instead-of-dropdown/41139/2 "2007-10-03T18:07:59Z")

</div>

For this kind of question you should really check the Rails list.

> **···**
>
> On Oct 3, 2007, at 12:09 PM, Remco Swoany wrote:
> 
> > Hi,
> > 
> > I am a RoR newby. The code below shows the categorie names, in a  
> > dropdown from the categories table and that works fine. But now i want  
> > to show the categories through checkboxen. How can i realise that??
> > 
> > \<select name="recipe[categorie\_id]"\>  
> > &nbsp;&nbsp;&nbsp;\<% @categories.each do |categorie| %\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<option value="\<%= categorie.id %\>"  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= 'selected' if categorie.id == @recipe.categorie\_id %\>\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= categorie.name %\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</option\>  
> > &nbsp;&nbsp;&nbsp;\<% end %\>  
> > &nbsp;&nbsp;\</select\>
> > 
> > Grtz..remco  
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Jeremy\_Woertink1](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@Jeremy\_Woertink1](https://rubytalk.org/u/Jeremy_Woertink1)\
**Post date:** [3 October 2007 19:00 UTC](https://rubytalk.org/t/checkbox-instead-of-dropdown/41139/3 "2007-10-03T19:00:13Z")

</div>

Remco Swoany wrote:

> Hi,
> 
> I am a RoR newby. The code below shows the categorie names, in a  
> dropdown from the categories table and that works fine. But now i want  
> to show the categories through checkboxen. How can i realise that??
> 
> \<select name="recipe[categorie\_id]"\>  
> &nbsp;&nbsp;&nbsp;\<% @categories.each do |categorie| %\>  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<option value="\<%= categorie.id %\>"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= 'selected' if categorie.id == @recipe.categorie\_id %\>\>  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= categorie.name %\>  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</option\>  
> &nbsp;&nbsp;&nbsp;\<% end %\>  
> &nbsp;&nbsp;\</select\>
> 
> Grtz..remco

Check out the rails doc [http://api.rubyonrails.org/](http://api.rubyonrails.org/)

You would put the check\_box inside an iteration. so..  
\<% @categories.each do |category| %\>  
&nbsp;&nbsp;\<%= check\_box(category, name) %\>  
\<% end %\>

~Jeremy

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
