Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select multiple options in a collection_select rails

I know how to put together a simple select box that takes its values from a model

<%= f.collection_select(:sector_id, Sector.all, :id, :name, :prompt => "Please Select a Sector") %>

My question is how do i allow a user to select multiple options and then store them in the model. I know i need to use

:multiple => true

But unsure on the syntax

Usually for multiple entries to a model i would use accepts_nested_attributes_for but am i correct in thinking i don't need to for this example?

Thanks

like image 278
Richlewis Avatar asked Aug 06 '13 08:08

Richlewis


1 Answers

Ok after some trial and error

<%= f.collection_select(:sector_id, Sector.all, :id, :name, {:prompt => "Please Select a Sector"}, {:multiple => true}) %>

lets me select multiple options

like image 149
Richlewis Avatar answered Oct 11 '22 22:10

Richlewis