Reputation: 3764
I am using the following code to select multiple values.
<select name="video" multiple="multiple" id="form-field-select-2" class="form-control">
<%video.each do |option|%>
<option><%=option%> </option>
<%end%>
</select>
But after submitting form its not giving all selected values,instead of its giving only the last selected value.
Please share if you have any idea about this issue.
Upvotes: 2
Views: 2331
Reputation: 33552
You can do this with select_tag
too
<%= select_tag 'video', options_from_collection_for_select(Video.all,"id","name"), :multiple => true, class: 'form-control'%>
For more details,see this API
Upvotes: 5
Reputation: 341
<select name="video[]" multiple="multiple" id="form-field-select-2" class="form-control">
<%video.each do |option|%>
<option><%=option%> </option>
<%end%>
</select>
You need to make sure that you are sending an array of answers by changing the name to video[]
Upvotes: 9