Rails AJAX Pagination with will_paginate plugin

Hi Guys,

If you are using will_paginate plugin for pagination then sometimes you may have a requirement for AJAX pagination.

I am damn sure that it is much simple instead of your thinking that how hard to do that.

First go through this link: http://weblog.redlinesoftware.com/2008/1/30/willpaginate-and-remote-links

It describes very well AJAX Pagination.

However I did some custom changes for my application.

In my view file I wrote:

<%= will_paginate must_have_item, :renderer => ‘RemoteLinkRenderer’, :remote => {:with => “‘must_have_items=true'”, :update => ‘must_have_gallery_whole’} %>

In above code,

  • must_have_item is an item array.
  • RemoteLinkRenderer is a file that you are supposed to include it in helper file(DO NOT CHANGE ANY CONTENT OF IT.)
  • must_have_items=true is a parameter that I passed with this request
  • must_have_gallery_whole is an id of div that updates after every AJAX request

Now In controller I wrote,

if request.xml_http_request?()
if params[:must_have_items]

In above code,

  • request.xml_http_request?() will get the AJAX request
  • params[:must_have_items] will be true as I passed “must_have_items=true” in view file.

So, write whatever you want after this two if conditions.

This is the way AJAX Pagination is working.

As I told you earlierĀ  it is very easy.

Now cheerssssss…….

About pulkitengg055
Hi I am Pancholi Pulkit.

One Response to Rails AJAX Pagination with will_paginate plugin

  1. Nisha says:

    hey, thanks. it is very helpful link!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: