限制will_paginate中的页面数 [英] Limit number of pages in will_paginate
本文介绍了限制will_paginate中的页面数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,在使用Sphinx时,搜索限制为1000个结果.但是,如果由will_paginate
生成的结果分页链接超过1000个,则不要考虑这一点,而是提供指向1000/per_page
之后的页面的链接.设置 max pages 或类似方法的明显方法是什么?
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屋!
查看全文