How can I make a post call instead of get call when i am paginating through pages using rails gem will_paginate?
In controller I have
@bills = Bill.where(some_condition) # returns collection @bills = @bills.paginate(:page => params[:page], :per_page => 5)
In view have used a table structure and at the end, have used
<%will_paginate%>, hence page 1 is showing up, but when I click on "next" or "page 2" then GET req. goes, I want to change it to POST call, is it possible?
I agree with antiqe's comment it's not right to paginate through POST request.
But if you have made up your mind to use POST read below:<ol><li>
By modifying the will_paginate
Source enchante's comment<blockquote>
use will_paginate doesn't support post by default, if you insist to use post, you need to customize LinkRender for will_paginate, see reference: github.com/mislav/will_paginate/wiki/Link-renderer</blockquote></li> <li>
By custom POST requests
From the <a href="https://groups.google.com/forum/#!topic/will_paginate/S_F46cTpGT8" rel="nofollow">source</a>:<blockquote>
the only correct way to do pagination in HTML would be to render a form inside which each pagination link is a submit button with the attribute name="page" set to page number as value. This form should also preserve existing search parameters, therefore it should have a hidden field for each of the current parameters. Clicking on the submit button will resubmit the advanced search with the page parameter changed.</blockquote></li> <li>
By custom ajax request
will_paginate don't support POST is that nobody uses it.
That's possible. But not suggest to do so.
@bills = @bills.paginate(:page => params[:page], :per_page => 5)
Here the <em>params[:page]</em> controls which page should be shown, include <em>:page</em> parameter in the post, that should work.
will_paginate doesn't support post by default, if you insist to use post, you need to customize LinkRender for will_paginate, see reference: github.com/mislav/will_paginate/wiki/Link-renderer