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.

Était-ce utile?

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

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top