I have the following form for search which should also perform filtering:
<%= form_tag search_index_path, method: :get, id: 'search_form' do %>
<%= text_field_tag :search, params[:search] %>
<%= check_box_tag 'filter param', 'yes', true %>
<%= submit_tag "Search", name: nil, class: 'btn' %>
<% end %>
What i'm trying to do now is to wrap parameters for filtering in a nested hash so that I have something as follows in params: {"utf8"=>"✓", "search"=>"term", "action"=>"index", "controller"=>"search", "filter" => {"field" => "value"}}
. Note that filter params are nested
I couldn't find a way to do this using standard rails form helpers. Is there any way to do that?
Use []
around the nested keys that you want. In your example, change your check_box to:
<%= check_box_tag 'filter[field]', 'value', true %>
If you wanted something in the form:
{ "filter" => { "subfilter" => { "field" => "value" } } }
You would add another []
:
<%= check_box_tag 'filter[subfilter][field]', 'value', true %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With