I have a page which is used for searching through listings by submitting data using the supplied forms. The form parameters are submitted via ajax (post request), a new record i
You can fix this by editing the pagination partials to manually strip out the params from the url, then add the page param back. I know this is a hack, but it seems like the quickest way to fix this issue if pagination is broken (as it was for me).
I'm expanding this from the solution posted in the GitHub bug report for this issue.
You have to edit each of the 5 pagination link partials: _page.html.erb
(by number), _first_page.html.erb
and _last_page.html.erb
, _prev_page.html.erb
and _next_page.html.erb
.
You can find the page number you want from the local variables made available in the partials: current_page
, page
, num_pages
.
If you haven't already, generate the pagination partials in your app by running rails g kaminari:views default
Then edit the partials as follows:
#_page.html.erb
<%
unless page.current?
url = url.split('?')[0] + '?page=' + page.to_s
end
%>
<%= link_to_unless page.current?, page, url, opts = {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
# _first_page.html.erb
<% url = url.split('?')[0] + '?page=1' %>
<%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote %>
# _prev_page.html.erb
<% url = url.split('?')[0] + '?page=' + (current_page.to_i - 1).to_s %>
<%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote %>
# _next_page.html.erb
<% url = url.split('?')[0] + '?page=' + (current_page.to_i + 1).to_s %>
<%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, :rel => 'next', :remote => remote %>
# _last_page.html.erb
<% url = url.split('?')[0] + '?page=' + num_pages.to_s %>
<%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote} %>