ruby-on-rails - 帮助解释 will_paginate 文档?

标签 ruby-on-rails ruby will-paginate

试图了解 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”)

pageper_pagefinder 很简单。

total_entriescount -- 不理解“仅在手动计数条目时使用?”他们是否设想了这样一种场景:您运行单独的计数查询,然后将结果作为选项传递给 paginate?在什么情况下您会这样做?

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

最佳答案

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

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

关于ruby-on-rails - 帮助解释 will_paginate 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1082927/

相关文章:

ruby - 将二进制字符串转换为 IEEE 754 float

javascript - js.erb 在本地工作但不在生产中

twitter-bootstrap - 在每个选项卡中使用 will_paginate 分页 Bootstrap 导航选项卡

ruby - 从 ruby​​ 哈希中获取所有 key

ruby-on-rails - Carreirwave - 如何直接从保存的文件名创建版本名称

ruby-on-rails - 如何将小数舍入到 Ruby 中的第一个有效数字

ruby-on-rails - 加速 ruby​​ select id 查询

ruby-on-rails - Anemone 可以抓取本地存储在我硬盘上的 html 文件吗?

ruby-on-rails - 为什么在生产中出现 "undefined method ' paginate'"错误?

ruby-on-rails - 弃用警告:初始化自动加载常量 ActionText::ContentHelper 和 ActionText::TagHelper