# Choose a pagination solution

**URL:** <https://www.ruby-forum.com/t/choose-a-pagination-solution/112920>\
**Category:** Rails\
**Created:** [August 24, 2007, 2:01pm UTC](https://www.ruby-forum.com/t/choose-a-pagination-solution/112920 "2007-08-24T14:01:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![niconoe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/a87d85/32.png) [@niconoe](https://www.ruby-forum.com/u/niconoe)\
**Post date:** [August 24, 2007, 2:01pm UTC](https://www.ruby-forum.com/t/choose-a-pagination-solution/112920/1 "2007-08-24T14:01:41Z")

</div>

Hi !

I’m looking for help to choose a pagination solution. As the built-in  
pagination is not very practical and will be soon deprecated, I was  
trying to finc something else.

My problem is that most solutions (for example paginating\_find) will  
replace the find method to add stuff. However, I’d like to find a more  
“flexible” solution, as I sometimes have to apply treatment to the  
retreived data. For example, I have a query that uses ‘OR’ to search on  
two different fields of the model, and I then use results.uniq! to  
remove duplicates. Of course, the pagination should apply to theses  
results, and not on the find result. I could put my uniq in the sql code  
(or use filters, but I need this in only one place in the app), but I  
think I could be more flexible if I could apply pagination on any array  
and not only the result of a find query.

what’s your opinion about the best way to solve this issue ?

Thanks in advance,

Nicolas

---

<div class="post-metadata">

**Author:** ![niconoe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/a87d85/32.png) [@niconoe](https://www.ruby-forum.com/u/niconoe)\
**Post date:** [August 24, 2007, 2:13pm UTC](https://www.ruby-forum.com/t/choose-a-pagination-solution/112920/2 "2007-08-24T14:13:46Z")

</div>

Just use will\_paginate

On 8/24/07, Nicolas N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> retreived data. For example, I have a query that uses ‘OR’ to search on
> 
> ## Nicolas
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Cheers!

- Pratik  
[http://m.onkey.org](http://m.onkey.org)

---

<div class="post-metadata">

**Author:** ![niconoe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/a87d85/32.png) [@niconoe](https://www.ruby-forum.com/u/niconoe)\
**Post date:** [August 24, 2007, 3:24pm UTC](https://www.ruby-forum.com/t/choose-a-pagination-solution/112920/3 "2007-08-24T15:24:11Z")

</div>

Well, when I read will\_paginate documentation, I still have the feeling  
that’s it’s designed to replace the find method, and not to (more  
genrally) handle a container.

Taken from the will\_paginate README :

@posts = Post.paginate\_by\_board\_id @board.id, :page =\> params[:page]

Yeah, +paginate+ works just like +find+ – it just doesn’t fetch all the  
records.  
Just don’t forget to tell it which page you want!

Pratik Naik wrote:

> Just use will\_paginate
> 
> On 8/24/07, Nicolas N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > retreived data. For example, I have a query that uses ‘OR’ to search on
> > 
> > ## Nicolas
> > 
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > >
> 
> –  
> Cheers!
> 
> - Pratik  
> [http://m.onkey.org](http://m.onkey.org)

---

<div class="post-metadata">

**Author:** ![niconoe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/a87d85/32.png) [@niconoe](https://www.ruby-forum.com/u/niconoe)\
**Post date:** [August 24, 2007, 8:37pm UTC](https://www.ruby-forum.com/t/choose-a-pagination-solution/112920/4 "2007-08-24T20:37:46Z")

</div>

On 8/24/07, Nicolas N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Well, when I read will\_paginate documentation, I still have the feeling  
> that’s it’s designed to replace the find method, and not to (more  
> genrally) handle a container.

There’s another plugin called “paginator” which you can read  
information about here: [http://rubyforge.org/projects/paginator](http://rubyforge.org/projects/paginator). From  
the Readme  
[http://viewvc.rubyforge.mmmultiworks.com/cgi/viewvc.cgi/trunk/README.txt?view=markup&root=paginator&pathrev=14](http://viewvc.rubyforge.mmmultiworks.com/cgi/viewvc.cgi/trunk/README.txt?view=markup&root=paginator&pathrev=14):

“Paginator doesn’t make any assumptions as to how data is retrieved; you  
just  
have to provide it with the total number of objects and a way to pull a  
specific  
set of objects based on the offset and number of objects per page.”

which seems like what you want. Personally, I use will\_paginate,  
since it adds a nice view method for you to automatically display the  
page links with a single line of code, nd you don’t need to count the  
number of objects manually like you do in paginator (I haven’t used  
paginator, so I’m just going by what’s in the readme file)

will\_paginate is pretty flexible in the way it works, if you need  
information on using it for complex queries (such as with  
scope-out-rails), check out the following site:

[http://zargony.com/2007/07/21/paginating-special-queries/](http://zargony.com/2007/07/21/paginating-special-queries/)

Adam

---

<div class="post-metadata">

**Author:** ![niconoe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/a87d85/32.png) [@niconoe](https://www.ruby-forum.com/u/niconoe)\
**Post date:** [August 25, 2007, 2:16pm UTC](https://www.ruby-forum.com/t/choose-a-pagination-solution/112920/5 "2007-08-25T14:16:20Z")

</div>

Just for the sake of offering another option: there’s also another major  
player in the pagination plugin game, paginating\_find [  
[Welcome cardboardrocket.com - BlueHost.com](http://cardboardrocket.com/pages/paginating_find) ]. Among the Rails  
developers I know it seems around half of us are using it. It’s  
completely a  
matter of style but I find paginating\_find’s interface to be a tad more  
elegant. They pretty much do the same things, just in slightly different  
ways. 🙂 And I always feel like it’s nice to have options to choose from  
instead of only being offered one solution.

RSL
