I have a feeling there is just a simple error somewhere but for the life of me I cannot find it. I have a filter model, and in it’s _form.html.erb there are various selects and collection selects. When the submit button is clicked I have used the debugger within the controller and found that several of the select boxes aren’t having their values being sent in the params. Here is the code with the buttons and other irrelevant things taken out:
<%= simple_form_for(@filter) do |f| %>
<div class="inputs">
<%= f.input :name %>
<%= f.input :scope, :collection => ["Global", "Group", "Private"], :include_blank => false %><br>
<p style="margin-left:190px;"><b>Users:</b></p>
<div style="float: left; width: auto; margin-left: 190px;">
<%= collection_select(:user, :id, User.all, :id, :full_name, {}, {:multiple => true, :size => 10}) %>
</div>
<%= select(:selected_users, :id, [], {}, {:size => 10, :style => "width:160px;", :multiple => true}) %>
<p style="margin-left:190px;"><b>Positions:</b></p>
<div style="float: left; width: auto; margin-left: 190px;">
<%= collection_select(:position, :id, Position.all, :id, :name, {}, {:size => 10, :multiple => true}) %>
</div>
<div style="float: left; width: auto; margin-left: 60px; margin-top: -120px;">
<%= collection_select(:selected_positions, :id, [], :id, :name, {}, {:size => 10, :style => "width:160px;", :multiple => true}) %>
</div>
<p style="margin-left:190px;"><b>States:</b></p>
<%= select("selected_statuses", "status", ["Approved", "Pending", "Deny"], {}, {:multiple => true, :size => 3, :style => "margin-left:190px;"})%>
</div>
<% end %>
In my params I get [:filter][:scope], [:filter][:name], [:user][:id], [:position][:id], and [:selected_statuses][:status], but none of the rest. Why is the select for the selected statuses working, while the select for the selected users isn’t? Or one of the position collection_selects but not the other? I’m very confused. And if it matters, the reason the selected_users and selected_positions are blank is because the options are added with javascript.
EDIT: After the javascript the HTML (with unnecessary bits omitted) is
<div class="inputs">
<div class="input string optional">
<label class="string optional" for="filter_name"> Name</label>
<input id="filter_name" class="string optional" type="text" size="50" name="filter[name]" maxLength="255">
</div>
<div class="input select optional">
<label class="select optional" for="filter_scope"> Scope</label>
<select id="filter_scope" class="select optional" name="filter[scope]">
<option value="Global">Global</option>
<option value="Private">Private</option>
</select>
</div>
<p style="margin-left:190px;">
<b>Users:</b>
</p>
<div style="float: left; width: auto; margin-left: 190px;">
<select id="user_id" size="10" name="user[id][]" multiple="multiple">
<option value="2">Ethan Webworm</option>
<option value="3">Matthew Barkbeetle</option>
<option value="4">Sara Caterpillar</option>
<option value="5">Olivia Daggermoth</option>
</select>
</div>
<select id="selected_users_id" style="width:160px;" size="10" name="selected_users[id][]" multiple="multiple">
<option value="2">Ethan Webworm</option>
<option value="3">Matthew Barkbeetle</option>
<option value="4">Sara Caterpillar</option>
</select>
<div style="float:left; width:auto; margin-left: 190px;>
<select id="position_id" size="10" name="position[id][]" multiple="multiple">
<option value="1">Manager</option>
<option value="2">CEO</option>
<option value="3">VP</option>
</select>
</div>
<div style="float: left; width: auto; margin-left: 60px; margin-top: -120px;">
<select id="selected_positions_id" style="width:160px;" size="10" name="selected_positions[id][]" multiple="multiple">
<option value="1">Manager</option>
</select>
</div>
<select id="selected_statuses_status" style="margin-left:190px;" size="3" name="selected_statuses[status][]" multiple="multiple">
<option value="Approved">Approved</option>
<option value="Pending">Pending</option>
<option value="Deny">Deny</option>
</select>
</div>
I just found the solution, which was indeed a simple embarrassing mistake… The reason the selected users/positions weren’t being sent in the parameters was just that while the options were added to the box in javascript they weren’t actually selected. Now I just need to find a way to select all of the options before sending the form. Thanks for the help!