我有一種感覺,只是一個簡單的錯誤,但對於我的生活我找不到它。我有一個過濾器模型,它的_form.html.erb中有各種選擇和集合選擇。當點擊提交按鈕時,我已經使用了控制器內的調試器,發現有幾個選擇框沒有在params中發送它們的值。下面是使用按鈕和其他不相干的事情代碼取出:Rails的collection_select沒有被髮送參數
<%= 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 %>
在我的PARAMS我得到[:過濾器] [:範圍],[:過濾器] [:名字],[:用戶] [: id],[:position] [:id]和[:selected_statuses] [:status],但沒有其他的。爲什麼所選狀態的選擇工作,而選定用戶的選擇不是?或者其中一個位置collection_select而不是另一個?我很困惑。如果這很重要,那麼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>
我們可以在用Javascript添加選項之後看到':selected_users'選擇**的結果HTML嗎? – deefour 2012-07-12 04:19:43
當然,我爲相關輸入添加了HTML。 – Alexei 2012-07-12 16:17:56
'params [:selected_users] [:id]'在'params'中無處?當表單提交時,你能否顯示完整的'params'轉儲?你有沒有像'before_filter'設置來清理表單數據? – deefour 2012-07-12 17:42:29