帮助解释will_paginate文档?
-
23-08-2019 - |
题
试图了解为will_paginate的选项 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”)
page
,per_page
,和finder
是直截了当的。
total_entries
和count
- 不明白“只使用,如果你手工统计条目?”难道他们设想在那里你会运行一个单独的数查询的情景,那么结果传递给paginate
作为一个选项?什么是在那里你会做的情况下?
“被传递给数附加选项” - 什么选择? “通过,”到???的count
方法
解决方案
默认情况下will_paginate使用计数(从的ActiveRecord ::计算 ),以找出你通过分页对象的总数。但如果你知道更好,或直计数将无法正常工作,你可以计算出,并提供:total_entries自己
在:计数参数是额外的参数给ActiveRecord的::计算#计数方法,如:不同。你可以看一下文档的完整列表。
其他提示
在total_entries和计数参数可当你想在同一列表进行分页不同型号,或者如果你想执行复杂查询中使用。只要你不需要它,不要担心。当你遇到你似乎无法解决问题,请稍后再来。
不隶属于 StackOverflow