Question: I have used will\_paginate in my rails application but i come across a situation where i need to use to will\_paginate inside a block where the page should not reload when i click the pagination number, could anyone help me saying how to integrate will\_paginate with ajax to avoid page reloading......?

Answer: 
I have a pagination javascript file

So in my index.html.erb file I addded 

```
<%=javascript_include_tag "pagination.js"%>

```

In pagination.js file

```
$(function(){
    $(".pagination a").live("click", function() {
        $.get(this.href, null, null, "script");
        return false;
    });
});

```

I fetched the model data like this in the index action. 

```
@employees = Employee.where("!is_deleted=?",1).paginate(:page=>params[:page] ,:per_page => 20)

```

and added this in the index.js.erb file

```
$("#employee_table").html("<%= escape_javascript(render("employees")) %>");

```

Here employee\_table is the id of the div where im displaying the data.

I have a file name will\_paginate\_array\_fix.rb in the config/initializers.  

This file will look like this

```
require 'will_paginate/array'

```

Thats why even though i use where it works because it supports for arrays also.
Here is how I set up things:

Let assume I have an `Item` model.

First in the index view, I render a partial where pagination is performed:

```
<div id="list">
 <%= render 'items/paginate_list', :items => @items %>
</div>

```

In the partial, I add a css class to my `will_paginate` statement:

```
items/_paginate_list.html.erb
<%=  will_paginate items,  :param_name => :page, :class => 'my_pagination' %>
# code displaying each item...

```

Then in the application.js, I catched events of clicking on the links of `my_pagination` class:

```
$(document).ready(function(){
  $('.my_pagination a').live("click",function(){
    $('.my_pagination').html('Page is loading, please wait...');
    $.get(this.href, null, null, 'script');
    return false;
  });
});

```

This way the call is performed to the controller in ajax through the `$.get` statement. The pagination bar displays a message that page is loading.

In the controller, I just have the usual:

```
class ItemsController < ApplicationController
  def index
    @items=Item.paginate(:page => params[:page], :per_page => 10)
  end
end

```

Finally, in the embedded js, I feed the partial with pagination to be reloaded:

```
items/index.js.erb
$("#list").html("<%= escape_javascript(render 'items/paginate_list', :items => @items) %>");

```

Hope this help.

Actually, It is roughly a quick summary of the [railscast](http://railscasts.com/episodes/174-pagination-with-ajax?view=asciicast) ;-)