I am trying to have the following HTML in my form:
<select name="user[language_ids][]"> <option value="">Please select</option> <option value="1" selected="selected">English</option> <option value="2">Spanish</option> </select> <select name="user[language_ids][]"> <option value="">Please select</option> <option value="1" selected="selected">English</option> <option value="2">Spanish</option> </select>
So that the user can select two languages during registration.
I tried with this:
<%= f.label :languages %> <%= f.collection_select(:language_ids, Language.all, :id, :name) %> <%= f.collection_select(:language_ids, Language.all, :id, :name) %>
And also with this:
<%= f.label :languages %> <%= f.collection_select(:language_ids[], Language.all, :id, :name) %> <%= f.collection_select(:language_ids[], Language.all, :id, :name) %>
After reviewing the answers, I tried with this:
<%= collection_select(:user, :language_ids, Language.all, :id, :name, {}, {:name => 'user[language_ids][]' }) %> <%= collection_select(:user, :language_ids, Language.all, :id, :name, {}, {:name => 'user[language_ids][]' }) %>
But the problem here is that both choices have the same identifier, and also they are not related to the form builder f
Any thoughts on how to do this?