我有一种感觉,某处只是一个简单的错误,但对于我的生活,我找不到它。我有一个过滤器模型,在它的 _form.html.erb 中有各种选择和集合选择。单击提交按钮时,我在控制器中使用了调试器,发现有几个选择框没有在参数中发送它们的值。这是删除按钮和其他不相关内容的代码:
<%= 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 %>
在我的参数中,我得到 [:filter][:scope]、[:filter][:name]、[:user][:id]、[:position][:id] 和 [:selected_statuses][:status] ,但其余的都没有。为什么选定状态的选择有效,而选定用户的选择无效?或者一个位置collection_selects 但不是另一个?我很困惑。如果重要的话, selected_users 和 selected_positions 为空白的原因是因为这些选项是使用 javascript 添加的。
编辑:在 javascript 之后,HTML(省略了不必要的位)是
<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>