Super Rails n00b here: Currently I have a form with the following code:
<%= f.collection_select :account_ids, @accounts, :id, :name, include_blank: true %>
If your parameter name ends in "[]", then all inputs with that name will be collated into an array with that name.
So, your select tag (in html) will be like
<select name="account_ids[]"><option>...
and to make this using the collection_select helper, try
<%= f.collection_select :account_ids, @accounts, :id, :name, {include_blank: true}, {:name => 'account_ids[]'} %>
You need to add one option :multiple
:
<%= f.collection_select :account_ids, @accounts,
:id, :name, { include_blank: true },
{ multiple: true } %>
Note: :multiple- If set to true
the selection will allow multiple choices.
I wrote a little snippet to test it. My code :
<%= form_for @track, url: fetch_path do |f| %>
<%= f.collection_select :label, @tracks, :id, :title, {include_blank: true}, {multiple: true} %>
<% end %>
Here is the page :
Or, if you really want to 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 the above line 3 times.