Question

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.

Was it helpful?

Solution

 <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[]

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top