문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top