Rails paginate existing array of ActiveRecord results

Posted by SaoiseK on Stack Overflow See other posts from Stack Overflow or by SaoiseK
Published on 2010-03-27T14:47:05Z Indexed on 2010/03/27 14:53 UTC
Read the original article Hit count: 224

Hello,

I generally use will_paginate for the pagination in my app, but have hit a stumbler on my search feature. I'm using Thinking Sphinx for doing my full-text search, which returns results paginated. The problem I'm having is that after I've received the results from Thinking Sphinx, I need to merge them with some other results and re-order them.

Once I've finished processing them I have an Array of results that is very different from the original from TS. As there could be 1000+ results in this Array Pagination is a necessity. The problem is that I can't figure out how to get will_paginate to play with an existing array.

I've done some research and it seems the only solutions to this problem are from several years ago and are based around the old built-in Paginator class. The most recent one I could find that makes use of will_paginate was from devchix from mid-2007: http://www.devchix.com/2007/07/23/will_paginate-array/comment-page-1/ - I've given this a go but it doesn't seem to do anything for me.

Are there any current methods for applying pagination (preferably via will_paginate) for existing arrays of AR results?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about pagination