Pagination of Complex Queries

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

However, now I’d like to paginate the recordset. Everything I’ve been
able
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
is
an array of AR) and create paginator objects for it?

Thanks

View this message in context:
http://www.nabble.com/Pagination-of-Complex-Queries-tf2030698.html#a5586011
Sent from the RubyOnRails Users forum at Nabble.com.

You can overide the default way that Paginate retrieves the records by
implementing your own “find_collection_for_pagination(model, options,
paginator)”. From http://api.rubyonrails.com/ 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
available.

David S.
[email protected]