# Need help in Ajax Pagination

**URL:** <https://www.ruby-forum.com/t/need-help-in-ajax-pagination/122647>\
**Category:** Rails\
**Created:** [December 10, 2007, 11:15am UTC](https://www.ruby-forum.com/t/need-help-in-ajax-pagination/122647 "2007-12-10T11:15:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 10, 2007, 11:15am UTC](https://www.ruby-forum.com/t/need-help-in-ajax-pagination/122647/1 "2007-12-10T11:15:55Z")

</div>

hi All,

i wants to implement ajax pagination but i am facing a lot of  
problem , i found i lots of links on google but their is no  
explanation like what object we have to pass and condition can any  
body help me out in this concern pls i need your help as soon as  
possible

thanks  
sachin

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 10, 2008, 1:42pm UTC](https://www.ruby-forum.com/t/need-help-in-ajax-pagination/122647/2 "2008-09-10T13:42:49Z")

</div>

removed\_email\_address@domain.invalid wrote:

> hi All,
> 
> i wants to implement ajax pagination but i am facing a lot of  
> problem , i found i lots of links on google but their is no  
> explanation like what object we have to pass and condition can any  
> body help me out in this concern pls i need your help as soon as  
> possible
> 
> thanks  
> sachin

HI,

With normal pagination code in controller you can use this code to  
perform pagination using Ajax.  
In following code use proper action name from controller in  
which you have done the pagination.

\<%if @photo\_pages.current.previous%\>  
\<%= link\_to\_remote (“previous”,  
:url=\>{:action=\>params[:redirect\_action], :page  
=\>@photo\_pages.current.previous,:redirect\_action=\>params[:redirect\_action],:id=\>params[:id]})%\>  
\<%end%\>

\<%if @photo\_pages.current.next%\>  
\<%= link\_to\_remote (“next”, :url=\>{:action=\>params[:redirect\_action],  
:page =\>  
@photo\_pages.current.next,:redirect\_action=\>params[:redirect\_action],:id=\>params[:id]})%\>  
\<%end%\>

Regards,  
kiran

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 10, 2008, 1:46pm UTC](https://www.ruby-forum.com/t/need-help-in-ajax-pagination/122647/3 "2008-09-10T13:46:06Z")

</div>

R U using will\_paginate?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 10, 2008, 2:53pm UTC](https://www.ruby-forum.com/t/need-help-in-ajax-pagination/122647/4 "2008-09-10T14:53:46Z")

</div>

Sijo Kg wrote:

> R U using will\_paginate?

Hi,  
I am using normal pagination code in controller as

@photo\_pages ,@photos = paginate\_collection @profile\_user,:per\_page =\>  
16,:page =\> @params[:page]

and in view using the code above specified.

Regards,  
kiran

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 11, 2008, 6:15am UTC](https://www.ruby-forum.com/t/need-help-in-ajax-pagination/122647/5 "2008-09-11T06:15:11Z")

</div>

Hi  
Add the following code to view\_helpers.rb .The file is in  
vendor/plugins/will\_paginate/lib/will\_paginate

def page\_link\_or\_span(page, span\_class = ‘current’, text = nil)  
text ||= page.to\_s  
if page and page != current\_page  
if update = @options[:update]  
@template.link\_to\_remote text, :update =\> update, :url =\>  
url\_options(page)  
else  
@template.link\_to text, url\_options(page)  
end  
else  
@template.content\_tag :span, text, :class =\> span\_class  
end

Then for ajax pagination in view do like  
\<%= will\_paginate @thecollectionyouwanttopaginate, :update=\>‘div’,  
:params=\>{:controller=\>‘controller\_name’,:action=\>‘action\_name’,:any\_additional\_parameters=\>@any\_additional\_parameters},  
:container =\> false %\>

```
And for normal pagination do what you are currenly doing

```

Sijo
