您好我有一个类似下面的搜索表单。我试图让下拉框保留提交时选择的值。
<%= search_form_for @search do |f| %>
<th><%= f.label :model_eq, "Search By Model" %>
<%= f.select :model_eq, options_for_select([["ALL"],
['Gender:Condition'],
['Naive:Stage'],['Race:Condition']],:selected => params[:model_eq]) %></th>
<%= f.submit "Search" , :name => nil%>
<% end %>
我想添加
:selected => params[:model_eq]
会保留所选值但不会。我也试过
:selected => params[:model]
但这也行不通。
答案 0 :(得分:1)
为此,您应该使用params[:q][:model_eq]
代替:
<%= f.select :model_eq, options_for_select([], :selected => params[:q][:model_eq]) %>