will_paginate 中的页数限制 [英] Limit number of pages in will_paginate
本文介绍了will_paginate 中的页数限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,当使用 Sphinx 时,搜索限制为 1000 个结果.但是,如果 will_paginate
生成的结果分页链接超过 1000 个,请不要考虑这一点,并提供超过 1000/per_page
的页面链接.设置最大页面或类似的东西的明显方法是什么?
So, when using Sphinx searches are limited to 1000 results. But, if there are more than 1000 results pagination links generated by will_paginate
don't take this into account, and provide links to pages beyond 1000/per_page
. Is the an obvious way setting a max pages or something similar?
干杯.
推荐答案
我发现最好的解决方案是这样做:
I found the best solution was to do this:
@results = Model.search(...)
if @results.total_pages >= (1000/Model.per_page)
class << @results; def total_pages; 1000/Model.per_page; end end
end
其中 1000 最好不是硬编码的 :).这可以让您免费获得 will_paginate 视图助手的正确行为,
Where the 1000 is preferably not hardcoded :). This gets you the correct behaviour of the will_paginate view helper for free,
这篇关于will_paginate 中的页数限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文