Rails搜索表单提交下拉列表后保留值

时间:2018-03-30 23:23:47

标签: ruby-on-rails dropdown ransack

您好我有一个类似下面的搜索表单。我试图让下拉框保留提交时选择的值。

 <%= 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]

但这也行不通。

1 个答案:

答案 0 :(得分:1)

为此,您应该使用params[:q][:model_eq]代替:

<%= f.select :model_eq, options_for_select([], :selected => params[:q][:model_eq]) %>