# Problem with multiple collection\_select

**URL:** <https://www.ruby-forum.com/t/problem-with-multiple-collection-select/89618>\
**Category:** Rails\
**Created:** [January 5, 2006, 12:33am UTC](https://www.ruby-forum.com/t/problem-with-multiple-collection-select/89618 "2006-01-05T00:33:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stan\_Shore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@Stan\_Shore](https://www.ruby-forum.com/u/Stan_Shore)\
**Post date:** [January 5, 2006, 12:33am UTC](https://www.ruby-forum.com/t/problem-with-multiple-collection-select/89618/1 "2006-01-05T00:33:31Z")

</div>

I am trying to allow the user to select more than one value from a  
selection list. Here is the code:

\<%= collection\_select(:transition, :complete\_tasks, @permissions, :id,  
:path, “”, {:size =\> “10”, :multiple =\> true} ) %\>

The multiple HTML option is supposed to allow multiple selections and,  
in fact, it does, although the HTML generated show the attribute as  
multiple=multiple when it should be just multiple.

The problem is that RAILS is only returning one value in  
transition.complete\_tasks.

Any idea what is going on?

Thanks!

---

<div class="post-metadata">

**Author:** ![Stan\_Shore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@Stan\_Shore](https://www.ruby-forum.com/u/Stan_Shore)\
**Post date:** [January 5, 2006, 1:51am UTC](https://www.ruby-forum.com/t/problem-with-multiple-collection-select/89618/2 "2006-01-05T01:51:36Z")

</div>

I ended up having to write a small, simple helper for this because I ran  
into the same problem. Basically the helper takes the same attributes as  
options\_from\_col… does, and also takes an array of selected objects  
and  
generates the list accordiningly. I dont have it on me now, but will  
post it  
tomorrow if I can and if you need it.

-Nick

---

<div class="post-metadata">

**Author:** ![Stan\_Shore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@Stan\_Shore](https://www.ruby-forum.com/u/Stan_Shore)\
**Post date:** [January 6, 2006, 11:01pm UTC](https://www.ruby-forum.com/t/problem-with-multiple-collection-select/89618/3 "2006-01-06T23:01:13Z")

</div>

Stan Shore wrote:

> I am trying to allow the user to select more than one value from a  
> selection list. Here is the code:
> 
> \<%= collection\_select(:transition, :complete\_tasks, @permissions, :id,  
> :path, “”, {:size =\> “10”, :multiple =\> true} ) %\>
> 
> The multiple HTML option is supposed to allow multiple selections and,  
> in fact, it does, although the HTML generated show the attribute as  
> multiple=multiple when it should be just multiple.

multiple=“multiple”

is the correct XHTML (in XHTML, all attributes have to have values)

> The problem is that RAILS is only returning one value in  
> transition.complete\_tasks.
> 
> Any idea what is going on?

I found this message from Michael K. in my mail archive:

On Apr 12, 2005 9:47 AM, Jason F. wrote: \>\>\> I'm trying to get multiple selected values from a tag into \>\>\> @params, but I can only get the first value in. This my code, something \> \> i believe to get multiple value params you use @request.params instead \> of @params. @params will always only give you the first one.

No need to do that. Just call your parameter something with [] on the  
end. That way rails knows it’s multiple.

i.e if you call it blah[] then @params[“blah”] yields an Array.

That was in a thread with subject “[Rails] Getting multiple values from  
 into @params?”, back in April 2005.

regards

Justin
