Rails paginate existing array of ActiveRecord results

我与影子孤独终老i 提交于 2019-12-23 09:37:30

问题


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?


回答1:


The official will_paginate wiki links to this, albeit from 2008:

http://www.pathf.com/blogs/2008/06/how-to-use-will_paginate-with-non-activerecord-collectionarray/




回答2:


I just posted how to use will_paginate on an array in rails 3. Look here for the answer I posted.

Ruby on Rails will_paginate an array



来源:https://stackoverflow.com/questions/2529684/rails-paginate-existing-array-of-activerecord-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!