Forum: Ruby on Rails Problem with multiple collection_select

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Stan Shore (Guest)
on 2006-01-05 01:33
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!
Nick S. (Guest)
on 2006-01-05 02:51
(Received via mailing list)
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
Justin F. (Guest)
on 2006-01-07 00:01
(Received via mailing list)
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:

<quote>
On Apr 12, 2005 9:47 AM, Jason F. <removed_email_address@domain.invalid> wrote:
 >>> I'm trying to get multiple selected values from a <SELECT> 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.
</quote>

That was in a thread with subject "[Rails] Getting multiple values from
<SELECT> into @params?", back in April 2005.

regards

   Justin
This topic is locked and can not be replied to.