Choosing Rails with multiple options sends only one

I have this form:

<form accept-charset="UTF-8" action="/contracts/<%= params[:id] %>/addConsultants" method="POST" id="updateConsultants"><!----> <div style="margin:0;padding:0;display:inline"> <input name="utf8" type="hidden" value="✓"> <input name="authenticity_token" type="hidden" value="<%= session[:_csrf_token] %>"> </div> <div class="consultant_selector"> <h2>Consultants</h2> <select name="consultants_available" size="10" multiple> <% @users.each do |u| %> <option value="<%= u[:id_user] %>"><%= u[:name] %></option> <% end %> </select> <ul> <li class="triangle_right" id="add_consultant"></li> <li class="triangle_left" id="remove_consultant"></li> </ul> <select name="consultants_selected" size="10" multiple> </select> </div> <div> <input type="submit" value="Mettre à jour" /> </div> </form> 

And in my controller:

  def add_consultants @contract = Contract.find(params[:id]) @consultants = params[:consultants_selected]; puts "------ Consultants: #{@consultants}" redirect_to contract_path end 

The idea is that I can select the names from the first selection, move them to the second by clicking on the triangle, and then submit the form to assign these names to the contract. However, when I do this, the puts call only displays one of the 3 IDs that I have in the second select (all three of them have the selected attribute for true ). How to get multiple values?

+1
ruby-on-rails forms
Dec 18 '13 at 9:50
source share
1 answer

Just found the answer here: stack overflow

Change the name of the second choose from:

 <select name="consultants_selected" size="10" multiple> </select> 

To:

 <select name="consultants_selected[]" size="10" multiple> </select> 

They worked.

+5
Dec 18 '13 at 10:34
source share



All Articles