2009-07-04 62 views
1

试图了解will_paginate的paginate方法的选项:帮忙翻译will_paginate文档?

:page — REQUIRED, but defaults to 1 if false or nil 
:per_page — defaults to CurrentModel.per_page (which is 30 if not overridden) 
:total_entries — use only if you manually count total entries 
:count — additional options that are passed on to count 
:finder — name of the ActiveRecord finder used (default: “find”) 

pageper_pagefinder非常简单。

total_entries and count - 不明白“只有手动计数条目时才使用”?他们是否设想了一种场景,您将运行单独的计数查询,然后将结果作为选项传递给paginate?你会这样做的情况是什么?

“传递给计数的附加选项” - 有哪些选项可用? “传递”到count方法???

回答

6

默认情况下,will_paginate使用count(来自ActiveRecord::Calculations)计算出您正在分页的对象总数。但如果你知道的更好,或者直接计数不起作用,你可以自己计算并提供:total_entries。

:count参数用于ActiveRecord :: Calculations#count方法的额外参数,如:distinct。您可以查看完整列表的文档。

+0

提供:total_entries似乎没有工作了。 COUNT(*)查询仍然在数据库中 – 2012-11-21 06:35:57

0

当您想要在同一个列表中对不同模型进行分页时,或者您想执行复杂查询时,可以使用total_entries和count参数。只要你不需要它,别担心。当遇到你无法解决的问题时,请回头看看。