Rails: Multiple dropdown menus collection_select -
super rails n00b here: have form following code:
<%= f.collection_select :account_ids, @accounts, :id, :name, include_blank: true %> and works how want have multiple drop down menus can select multiple accounts. not want multiple select on same dropdown.
if this:
<%= f.collection_select :account_ids, @accounts, :id, :name, include_blank: true %> <%= f.collection_select :account_ids, @accounts, :id, :name, include_blank: true %> <%= f.collection_select :account_ids, @accounts, :id, :name, include_blank: true %> only last selection appears in params. how can make params this:
"journal"=>{"account_ids"=>["1","2","3"]} can collection.select or should using different? appreciated. thanks!
you need add 1 option :multiple :
<%= f.collection_select :account_ids, @accounts, :id, :name, { include_blank: true }, { multiple: true } %> note: :multiple- if set true selection allow multiple choices.
i wrote little snippet test it. code :
<%= form_for @track, url: fetch_path |f| %> <%= f.collection_select :label, @tracks, :id, :title, {include_blank: true}, {multiple: true} %> <% end %> here page :

or, if want duplicate:
<% klass = f.object.class.model_name.param_key %> <%= f.collection_select :account_ids, @accounts, :id, :name, { include_blank: true } , { name: "#{klass}[account_ids][]" } %> write above line 3 times.
Comments
Post a Comment