过滤器在请求后消失

Filters disappear after the request

我有这个选择,用户可以过滤他的搜索:

他们正在做他们应该做的事情。但是在提交之后,这些值从选择中消失了。

问题是:如何在用户提交后保留这些过滤器?

这是我的代码:

<%= form_tag filter_vehicles_path, method: 'get', id: 'form_filter_vehicles'  do %>
    <h4><strong>

      <span>Fabricante</span>
      <%= collection_select :manufacturer, :manufacturer_id, Manufacturer.joins(:vehicles).uniq, :id, :name, {include_blank: true}, {class: "manufacturer_dropdown"} %>

      <span>Modelo</span>
      <%= grouped_collection_select :model, :model_id, Manufacturer.order(:name), :models, :name,  :id, :name, {include_blank: true}, {class: "model_dropdown", data: {models: @models}} %>

      <span>Preço</span>
      <%= select_tag :price_start, options_for_select([price(250), price(500), price(1000), price(2000), price(3000), price(4000), price(5000), price(6000), price(7000), price(8000), price(9000),price(10000), price(12000), price(14000), price(16000), price(18000), price(20000), price(22000), price(24000), price(26000), price(28000), price(30000), price(32000), price(34000), price(36000), price(38000), price(40000), price(50000), price(60000), price(70000), price(80000), price(90000), price(100000), price(150000), price(200000)]), include_blank: true, class:"select2PriceFrom" %>

      <%= select_tag :price_ending, options_for_select([price(250), price(500), price(1000), price(2000), price(3000), price(4000), price(5000), price(6000), price(7000), price(8000), price(9000),price(10000), price(12000), price(14000), price(16000), price(18000), price(20000), price(22000), price(24000), price(26000), price(28000), price(30000), price(32000), price(34000), price(36000), price(38000), price(40000), price(50000), price(60000), price(70000), price(80000), price(90000), price(100000), price(150000), price(200000)]), include_blank: true, class:"select2PriceTo" %>

      <span>Ano</span>
      <%= select_tag :year_start, options_for_select((1990..Date.today.year).to_a.reverse + ["1980", "1970", "1960", "1950", "1940", "1930", "1920", "1910", "1900"]), {include_blank: true, maxlength: 4, class:"select2YearFrom"} %>
      <%= select_tag :year_ending, options_for_select((1990..Date.today.year).to_a.reverse + ["1980", "1970", "1960", "1950", "1940", "1930", "1920", "1910", "1900"]), {include_blank: true, maxlength: 4, class:"select2YearTo"} %>

      <span>Quilómetros</span>

      <%= select_tag :kms_start, options_for_select([ kms(5000), kms(10000), kms(15000), kms(20000), kms(25000), kms(30000), kms(35000), kms(40000), kms(45000), kms(50000), kms(75000), kms(100000), kms(125000), kms(150000), kms(175000), kms(200000), kms(225000), kms(250000), kms(275000), kms(300000), kms(350000), kms(400000), kms(500000)]), include_blank: true, class:"select2KmFrom" %>

      <%= select_tag :kms_ending, options_for_select([ kms(5000), kms(10000), kms(15000), kms(20000), kms(25000), kms(30000), kms(35000), kms(40000), kms(45000), kms(50000), kms(75000), kms(100000), kms(125000), kms(150000), kms(175000), kms(200000), kms(225000), kms(250000), kms(275000), kms(300000), kms(350000), kms(400000), kms(500000)]), include_blank: true, class:"select2KmTo" %>

      <%= submit_tag "Pesquisar" %>
    </strong></h4>
  <% end %>

顺便说一句,我正在使用 Select2.js 库。

提前致谢!

将您在 html 上选择的输入添加到您的输入中,发送请求中的参数。像这样

selected: params[:param_name]

所以你将它们添加到每个输入中,就像这样

<%= select_tag :price_start, options_for_select([price(250), price(500), price(1000), price(2000), price(3000), price(4000), price(5000), price(6000), price(7000), price(8000), price(9000),price(10000), price(12000), price(14000), price(16000), price(18000), price(20000), price(22000), price(24000), price(26000), price(28000), price(30000), price(32000), price(34000), price(36000), price(38000), price(40000), price(50000), price(60000), price(70000), price(80000), price(90000), price(100000), price(150000), price(200000)]), include_blank: true, class:"select2PriceFrom", selected: params[:price_start] %>

<%= select_tag :price_ending, options_for_select([price(250), price(500), price(1000), price(2000), price(3000), price(4000), price(5000), price(6000), price(7000), price(8000), price(9000),price(10000), price(12000), price(14000), price(16000), price(18000), price(20000), price(22000), price(24000), price(26000), price(28000), price(30000), price(32000), price(34000), price(36000), price(38000), price(40000), price(50000), price(60000), price(70000), price(80000), price(90000), price(100000), price(150000), price(200000)]), include_blank: true, class:"select2PriceTo", selected: params[:price_ending] %>