There are two forms on the site, the 1st is the product filter, the 2nd is the sorting (drop-down list). I need that when selecting parameters in the filter, I could sort by the filtered parameters.

Now I did this: I added the hidden_field_tag ​​in each form and specified the url parameter as a value:

= hidden_field_tag :color, params[:color] 

But this option works with errors (parameters are duplicated in url)

Found an option how to do it all with the help of the link:

 = link_to 'Сортировка по цвету', root_path(params.merge({color: :white})) 

But to apply this solution to the drop-down list (select_tag) does not work.

  • And how is the sorting done? AJAX? It is not very clear why the parameter is duplicated, do you add it to the current URL? - cheops
  • Without ajax. Yes, to the current url. Cured duplication, - if params[:sort].present? = hidden_field_tag :sort, params[:sort] - if params[:sort].present? = hidden_field_tag :sort, params[:sort] but in my opinion some kind of bike is obtained) - Pavel Scheglov
  • You can make one form for sorting and filtering. To do this, in the select tag, with the sorting options, you must specify the form attribute that contains the filter form identifier. - MAXOPKA
  • And how to specify such an identifier? - Pavel Scheglov
  • For example, the form of the filter <form id="my_filter_form" >...</form> . Select sort options <select form="my_filter_form" >...</select> - MAXOPKA

0