Choose a pagination solution

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

Just use will_paginate

On 8/24/07, Nicolas N. [email protected] wrote:

retreived data. For example, I have a query that uses ‘OR’ to search on

Nicolas

Posted via http://www.ruby-forum.com/.


Cheers!

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. [email protected] wrote:

retreived data. For example, I have a query that uses ‘OR’ to search on

Nicolas

Posted via http://www.ruby-forum.com/.


Cheers!

On 8/24/07, Nicolas N. [email protected] 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. From
the Readme
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/

Adam

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 ]. 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. :slight_smile: And I always feel like it’s nice to have options to choose from
instead of only being offered one solution.

RSL