Rails 搜索表单在提交下拉列表后保留值
Rails Search form Keep values after submission of drop down
您好,我有一个如下所示的搜索表单。我试图让下拉框保留提交时选择的值。
<%= 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]
但这也行不通。
为此,您应该使用 params[:q][:model_eq]
:
<%= f.select :model_eq, options_for_select([], :selected => params[:q][:model_eq]) %>
您好,我有一个如下所示的搜索表单。我试图让下拉框保留提交时选择的值。
<%= 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]
但这也行不通。
为此,您应该使用 params[:q][:model_eq]
:
<%= f.select :model_eq, options_for_select([], :selected => params[:q][:model_eq]) %>