LoginSignup
4
7

More than 5 years have passed since last update.

[rails] form_tag method: getでURL params を送る方法

Last updated at Posted at 2019-01-04

1, URLにselectboxを使ってuserにparamsを送る
2, ついでにselectboxで選んだらすぐsubmitしたい。

[_filter.html.erb]

<%= form_tag request.path, method: :get do %>
  <%= hidden_field_tag :size, params[:size] %>
  <%= hidden_field_tag :view, params[:] %>
  <%= select_tag(:sort,
      options_for_select(@product_filter.sort_select_collection, 
      { selected: params[:sort] || 'newest' }), 
       class: 'select-drop', 
       onchange: 'this.form.submit();') 
  %>
<% end %>

controller側で、params[:size],params[:color]で受け取れる。

4
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
7