# HELP: multiple select list in ror

**URL:** <https://www.ruby-forum.com/t/help-multiple-select-list-in-ror/101225>\
**Category:** Rails\
**Created:** [August 3, 2006, 5:42pm UTC](https://www.ruby-forum.com/t/help-multiple-select-list-in-ror/101225 "2006-08-03T17:42:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbrady010](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/919ad9/32.png) [@dbrady010](https://www.ruby-forum.com/u/dbrady010)\
**Post date:** [August 3, 2006, 5:42pm UTC](https://www.ruby-forum.com/t/help-multiple-select-list-in-ror/101225/1 "2006-08-03T17:42:53Z")

</div>

Hi

Search doesn’t seem to be working so my apologies if this has come up  
before.

I have some simple code in a view that generates a multiple select:

\<% for m in Menu.find(:all) %\>

" else "\>" end %\> \<%= m.name %\>

\<% end %\>

It generates a nice multiple select and when used to view a menu section  
it correctly displays the menus it belongs to even if there are  
multiple. However, when saving it only returns one value in the params  
even though I select several. My params with 2 menus selected looks like  
this:

Parameters: {“commit”=\>“Create”, “action”=\>“create”,  
“controller”=\>“menu\_sections”, “menu\_section”=\>{“name”=\>“test Menu”,  
“display\_name”=\>"", “position”=\>“56”}, “menu\_select”=\>“1”}

I know there must be something simple wrong but I can’t see what. Why  
isn’t the menu\_select an array of id’s?

Thanks

ps anybody got a nice acts\_as\_multiple\_selection ?

---

<div class="post-metadata">

**Author:** ![dbrady010](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/919ad9/32.png) [@dbrady010](https://www.ruby-forum.com/u/dbrady010)\
**Post date:** [August 3, 2006, 11:12pm UTC](https://www.ruby-forum.com/t/help-multiple-select-list-in-ror/101225/2 "2006-08-03T23:12:53Z")

</div>

Hi Donald,

Let’s say that you have a habtm association between menu and user, check  
this code snipset:

\<% Menu.find(:all, :order =\> "name").each\_with\_index do |k, i| -%\> - \<%= check\_box\_tag('user[menu\_ids][]', k.id, @user.menus.include?(k)) %\> \<%= k.name %\> 
\<% end %\>

Jean-Etienne

---

<div class="post-metadata">

**Author:** ![dbrady010](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/919ad9/32.png) [@dbrady010](https://www.ruby-forum.com/u/dbrady010)\
**Post date:** [August 4, 2006, 12:03am UTC](https://www.ruby-forum.com/t/help-multiple-select-list-in-ror/101225/3 "2006-08-04T00:03:07Z")

</div>

Thanks Jean-Etienne

Here’s the params with your code:

Parameters: {“commit”=\>“Edit”, “action”=\>“update”, “id”=\>“1”,  
“controller”=\>“menu\_sections”, “menu\_section”=\>{“name”=\>“Appetizers”,  
“menu\_ids”=\>[“2”, “1”], “display\_name”=\>"", “position”=\>“1”},  
“menu\_select”=\>“2”}

So individual check boxes work, but why not a multiple select? From a UI  
standpoint it’s a lot easier.

Jean-Etienne D. wrote:

> Hi Donald,
> 
> Let’s say that you have a habtm association between menu and user, check  
> this code snipset:
> 
> \<% Menu.find(:all, :order =\> "name").each\_with\_index do |k, i| -%\> - \<%= check\_box\_tag('user[menu\_ids][]', k.id, @user.menus.include?(k)) %\> \<%= k.name %\> 
> \<% end %\>
> 
> Jean-Etienne

---

<div class="post-metadata">

**Author:** ![dbrady010](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/919ad9/32.png) [@dbrady010](https://www.ruby-forum.com/u/dbrady010)\
**Post date:** [August 4, 2006, 12:37am UTC](https://www.ruby-forum.com/t/help-multiple-select-list-in-ror/101225/4 "2006-08-04T00:37:00Z")

</div>

Just figured it out. The

\<select name=“menu\_select[]” must have the [] other wise it only returns  
one.

Jean-Etienne code gave me the hint and also this:

[http://www.forthecode.com/user/index/17](http://www.forthecode.com/user/index/17)

Thanks

Donald B. wrote:

> Thanks Jean-Etienne
> 
> Here’s the params with your code:
> 
> Parameters: {“commit”=\>“Edit”, “action”=\>“update”, “id”=\>“1”,  
> “controller”=\>“menu\_sections”, “menu\_section”=\>{“name”=\>“Appetizers”,  
> “menu\_ids”=\>[“2”, “1”], “display\_name”=\>“”, “position”=\>“1”},  
> “menu\_select”=\>“2”}
> 
> So individual check boxes work, but why not a multiple select? From a UI  
> standpoint it’s a lot easier.
> 
> Jean-Etienne D. wrote:
> 
> > Hi Donald,
> > 
> > Let’s say that you have a habtm association between menu and user, check  
> > this code snipset:
> > 
> > \<% Menu.find(:all, :order =\> "name").each\_with\_index do |k, i| -%\> - \<%= check\_box\_tag('user[menu\_ids][]', k.id, @user.menus.include?(k)) %\> \<%= k.name %\> 
> > \<% end %\>
> > 
> > Jean-Etienne
