[[+content_image]]
D
D
dexdev2014-10-16 23:19:26
Ruby on Rails
dexdev, 2014-10-16 23:19:26

How to leave the required params in the url?

There is a form

<%= form_tag static_pages_mytasks_path({category_id: params[:category_id]}), :method => 'get' do |f| %>
      <%= select_tag(:status, options_for_select([['опубликовано', 1], ['черновик', 2], ['удалено', 3]],{ selected: params[:status]}), prompt: "Изменить статус", class: "form-control", onchange: "this.form.submit();") %>
    </div>
    <div class="all_post_city_select">
      <%= select_tag(:city_id, options_for_select([['Москва', 1], ['Питер', 2], ['Казань', 3]], {selected: params[:city_id]}),prompt: "Выбрать город",class: "form-control", :onchange => "this.form.submit();") %>
      <% end %>

and there are links
<% Category.where(parent_id: 0).each do |category| %>
    <li class="list-group-item">
      <%= link_to category.name, static_pages_mytasks_path(category_id:category.id, status: params[:status], city_id: params[:city_id]) %>
      <% end %>

If you first select a city or status and then click on the links, then everything is fine, but if you first click on the links and then select the city and status, then the categories fly off, tell me how to leave params[:category_id] in the form?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
Alexander Shcheglov, 2014-10-17
@AdilA

Add input type="hidden" to the form with the category value:

<%= hidden_field_tag :category_id, params[:category_id] %>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question