我正在使用collection_select從下拉列表中選擇一個選項。當我提交表單時,我想發送多個參數到params散列表中。在這種情況下,'team_id'和'team_name'。 team_id在params散列中顯示得很好。 'team_name'是顯示在下拉列表中的值。rails 4,collection_select,將多個屬性傳入表單提交的參數哈希值?
view.html.erb
<%= form_for @carpool do |f| %>
<h3>Select Team</h3>
<div class="form-group">
<%= f.collection_select :team_id, @ts_teams ? @ts_teams : [], :id, :name, include_blank: true %>
</div>
<%= f.submit 'Create Carpool', :class => 'button left' %>
<% end %>
PARAMS哈希
{"utf8"=>"✓", "authenticity_token"=>"bdazhLNLZ0QunrpJT7Gu63ipX76WME+ENSxL/B0XGeFL/GP5nishozmQENe22aelfcnnhnPBr4B35MeRL+kJLQ==", "carpool"=>{"team_id"=>"1923565"}, "commit"=>"Create Carpool", "controller"=>"carpools", "action"=>"create"}
如何傳遞到TEAM_NAME params哈希表?
你想在你的控制器方法用'team_name'做什麼?是否有你想從params散列中得到它的原因? – MarsAtomic
是的 - 我想創建一個拼車對象 - 我想將拼車對象的'name'屬性設置爲團隊的名稱... team_name。也許有一個更簡單的方法來做到這一點... – matthewalexander