# Problem: using will\_paginate with Ajax

**URL:** <https://www.ruby-forum.com/t/problem-using-will-paginate-with-ajax/157982>\
**Category:** Rails\
**Created:** [January 17, 2009, 9:05am UTC](https://www.ruby-forum.com/t/problem-using-will-paginate-with-ajax/157982 "2009-01-17T09:05:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tuhin\_cse99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@tuhin\_cse99](https://www.ruby-forum.com/u/tuhin_cse99)\
**Post date:** [January 17, 2009, 9:05am UTC](https://www.ruby-forum.com/t/problem-using-will-paginate-with-ajax/157982/1 "2009-01-17T09:05:19Z")

</div>

I want to use pagination with ajax. I have used will\_paginate then add  
code to support ajax pagination.  
I have tried with partial with when I use the code  
in index.html.erb

 \<%= render :partial =\> 'contents' %\>

Partial view: \_contents.html.erb  
\<%= will\_paginate @collection, :renderer =\> ‘RemoteLinkRenderer’,  
:remote =\> {:update =\> ‘container’} %\>

in controller the index action :  
respond\_to do |format|  
format.html { render :partial =\> ‘container’ }  
format.xml { render :xml =\> @posts }  
end

and I am using the index action in the controller.  
It just show only the partial not the total page with the partial  
display.

Please help me

---

<div class="post-metadata">

**Author:** ![tuhin\_cse99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@tuhin\_cse99](https://www.ruby-forum.com/u/tuhin_cse99)\
**Post date:** [January 19, 2009, 3:07am UTC](https://www.ruby-forum.com/t/problem-using-will-paginate-with-ajax/157982/2 "2009-01-19T03:07:08Z")

</div>

On Sat, Jan 17, 2009 at 3:05 AM, Ruhul A. \<  
removed\_email\_address@domain.invalid\> wrote:

> \<%= will\_paginate @collection, :renderer =\> ‘RemoteLinkRenderer’,  
> display.
> 
> Please help me

In my controller, I have:

```
respond_to do |format|
  format.html # index.html.erb
  format.xml { render :xml => @documents }
  format.js do
    render :update do |page|
      page.replace_html('documents_table',
                        :partial => 'documents_table',
                        :locals => {:documents => @documents})
    end
  end
end

```

In index.html.erb, I have

 \<%= render :partial =\> 'documents\_table', :locals =\> {:documents =\> @documents} %\>

That way, when I first render the page, I get the total page, but when I  
click on the page number links I just update the div with the data.

Hope this helps.

–wpd

---

<div class="post-metadata">

**Author:** ![tuhin\_cse99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@tuhin\_cse99](https://www.ruby-forum.com/u/tuhin_cse99)\
**Post date:** [January 26, 2009, 9:53am UTC](https://www.ruby-forum.com/t/problem-using-will-paginate-with-ajax/157982/3 "2009-01-26T09:53:47Z")

</div>

Patrick D. wrote:

> In my controller, I have:
> 
> ```
> respond_to do |format|
> format.html # index.html.erb
> format.xml { render :xml => @documents }
> format.js do
> render :update do |page|
> page.replace_html('documents_table',
> :partial => 'documents_table',
> :locals => {:documents => @documents})
> end
> end
> end
> 
> ```
> 
> In index.html.erb, I have
> 
> \<%= render :partial =\> 'documents\_table', :locals =\> {:documents =\> @documents} %\>

hi Patrick D.,  
Thx for you reply.I have tried according to your code  
but it don’t display result but shows the  
javascript code with the result. Below is the javascript that output in  
the html page when I click the next link.

try { Element.update(“votedtop20”, " \n\n\n\n\n  
\n \n \n hjbnj\n \n  
\n \n  
\n\n"); } catch (e) { alert(‘RJS error:\n\n’ + e.toString());  
alert(‘Element.update(“votedtop20”, " \n\n\n\n\n  
\n \n \n hjbnj\n \n  
\n \n  
\n\n");’); throw e }

Please help me.Thx in advance.  
Amin

---

<div class="post-metadata">

**Author:** ![tuhin\_cse99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@tuhin\_cse99](https://www.ruby-forum.com/u/tuhin_cse99)\
**Post date:** [January 26, 2009, 3:40pm UTC](https://www.ruby-forum.com/t/problem-using-will-paginate-with-ajax/157982/4 "2009-01-26T15:40:34Z")

</div>

On Mon, Jan 26, 2009 at 3:53 AM, Ruhul A. \<  
removed\_email\_address@domain.invalid\> wrote:

> > ```
> > :partial => 'documents_table',
> > 
> > ```
> 
> alert(‘Element.update(“votedtop20”, " \n\n\n\n\n  
> \n \n \n hjbnj\n \n  
> \n \n  
> \n\n");’); throw e }
> 
> Please help me.Thx in advance.  
> Amin
> 
> Golly, I don’t know. I would guess that if you are seeing javascript in  
> your browser, then somehow you are not responding to a javascript  
> request,  
> but I really don’t understand enough of how things work “under the hood”  
> to  
> know how that might happen.

–wpd
