Pagination of Complex Queries

I’ve created a class method in my model called find_filtered. The intent
that I take various params that the user has submitted, and let the
build the query and return the AR collection, which is exactly what

However, now I’d like to paginate the recordset. Everything I’ve been
to find about pagination presumes that you have no pre-existing AR
collection. Is there a way to use the result of my find_filtered (which
an array of AR) and create paginator objects for it?


View this message in context:
Sent from the RubyOnRails Users forum at

You can overide the default way that Paginate retrieves the records by
implementing your own “find_collection_for_pagination(model, options,
paginator)”. From under paginate:

*find_collection_for_pagination*(model, options, paginator)

Returns a collection of items for the given model and
+options[conditions]+, ordered by +options[order]+, for the current
page in the given paginator. Override this method to implement a
custom finder.

I just had to do this for a collection where I was retrieving values
from two different databases and merging them before displaying them and
it works just great. Look at the “show source” to see what options are

David S.
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs