Paginate a collection


#1

hi i want to paginate a collection found by complex sql query
how can i do
thanks


#2

On 3/18/06, john carter removed_email_address@domain.invalid wrote:

hi i want to paginate a collection found by complex sql query
how can i do
thanks

Check out this page:
http://www.bigbold.com/snippets/posts/show/389


#3

thank you for your answer
i’ve tested this code but only the first page is displayed
i cant display the others pages


#4

On 3/19/06, john carter removed_email_address@domain.invalid wrote:

thank you for your answer
i’ve tested this code but only the first page is displayed
i cant display the others pages

Check out the comments below the code snippet, at the original URL.
You need to include the :page => some_variable option manually when
using that code.
One way would be to say:
page = params[:page] || 1
paginate_collection(:page => page) { big complex query here }

One thing to be aware of is that paginating in memory like this can be
much slower than having your database do it. You should only use this
method when paginating something that can’t be made compatible with
‘LIMIT’ and ‘OFFSET’.