mutiple select

Hello:
   How do i make a mutiple select list for "nomodel" objects?I made that
by using something like:<select name="" multiple="mutiple"><%=option
groups collection for select(....)-%></select>.But when i select mutiple
items and submit them,I can only get one selected item?
   Who can help me?

Who can help me?

Guo Yangguang wrote:

   How do i make a mutiple select list for "nomodel" objects?I made that
by using something like:<select name="" multiple="mutiple"><%=option
groups collection for select(....)-%></select>.But when i select mutiple
items and submit them,I can only get one selected item?

Add:

:multiple => true

to the options parameter to your select call.

See:
http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M001037

Thank you for your reminding!

Hello:
   I have added the :multiple=>true to the select_tag.But still,only one
selected item was submitted when selected the mutiple items.I don't know
why?

<%form_remote_tag(:update=>"give",:url=>{:action=>"gift_given",:id=>gift})
do-%>
  <%=select_tag("products",option_groups_from_collection_for_select
(@ng_category_groups,"options","name","product_id","product_name"),:multiple=>true)-%>
  <p><%=submit_tag "give"-%></p>
<%end-%>

who can help me?

Guo Yangguang wrote:

   I have added the :multiple=>true to the select_tag.But still,only one
selected item was submitted when selected the mutiple items.I don't know
why?

So you can select multiple items? If so, what are the parameters
recorded in your log file when posting the form? And what is your code
in the controller that receives the form data?

If you can select multiple items, then there should be multiple items in
the parameters, so if this is still not working for you I suspect it is
because of the way you read the values...

I can select multiple items using mouse while pushing ctrl key,but can
not select multiple items only using mouse.After selecting mutiple items
and submitting, there is only one item submitted in the params.
  Collection:@ng_category_groups is the return value of some method
which i called in the view in the help file.I have not designed the
method to recieve
form data because the recieved params include only one item.

Mark Bush wrote:

Guo Yangguang wrote:

I can select multiple items using mouse while pushing ctrl key,but can
not select multiple items only using mouse.

This is normal behaviour.

After selecting mutiple items
and submitting, there is only one item submitted in the params.

Having looked at your view again, the name used is "products" which will
create a select returning a single item (even though multiple can be
selected). To return multiple items, the name must end in "[]", so:

<%=select_tag("products[]",option_groups_from_collection_for_select
(@ng_category_groups,"options","name","product_id","product_name"),:multiple=>true)-%>

If this is in a form for a specific object (say "my_object") and you
want the products returned to be grouped in the params hash for this
object, then use the name "my_object[products][]".

Thank you!I think i can manage it now according your advice.

Mark Bush wrote: