I have a Rails app and using ruby 2.3.3.
For my forms I use simple_form, Ransack for the filtering and will_paginate.
I have 'set_per_page' dropdown,so Users can select if the want to see 20, 200 or 200 posts in the table.
= form_tag({ action: "index"}, { method: "get", id: "post_index"}) do
=select_tag :per_page, otions_for_select( [20,200,2000], params[:per_page].to_i )
My javascript is like this:
$(document).ready(function() {
$("#per_page").change(function() {
$("#post_index").submit();
});
});
So when a user changes the dropdown, it will render the action 'index' again and sets the per_page parameter to the selected value. So far so good, but when I submit the Ransack parameters are gone.
When I filter with Ransack, the URL is:
http://localhost:3001/posts?q[name_eq]=Foo&q[title_eq]=Bar
When I select the 'per_page' dropdown, my URL will become:
http://localhost:3001/posts?per_page=200
How can I parse the params of the Ransack call, into the per_page call. So I will have a URL like this:
http://localhost:3001/posts?q[name_eq]=Foo&q[title_eq]=Bar&per_page=200
Edit:
I tried to add the Ransack parameters in a hidden field like this:
= form_tag({ action: "index"}, { method: "get", id: "post_index"}) do
=select_tag :per_page, otions_for_select( [20,200,2000], params[:per_page].to_i )
=hidden_field_tag :q, params[:q] if params[:q].present?
But this results in a error:
undefined method `merge' for "#<ActionController::Parameters:0x175c6110>":String