将分页:限制结果数量
我正在使用 ruby 的 will paginate gem。我正在使用将分页来获取一群人并在字段上进行排序。我想要的只是其中的前 100 个。本质上都是顶尖人物。我似乎无法做到这一点。我该怎么办呢?谢谢
Im using the will paginate gem for ruby. I am using will paginate to get a bunch of people and sorting on a field. What I want is only the first 100 of those. Essentially the top people. I cant seeem to do this. How would i go about it? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知, will_paginate 没有为此提供选项,我也只是在其源代码中找到了一个根来检查,但是如果您不介意在您的条件中使用子查询,则可以完成...
替换a_field 与您排序的字段,这应该适合您。
(注意,上面使用当前版本的 will_paginate (3.0.2) 的语法,但相同的概念也适用于旧版本以及使用选项哈希)
As far as my knowledge goes will_paginate doesn't provide an option for this, I just had a root around in its source too to check, but if you don't mind having a subquery in your conditions it can be done...
Replace a_field with the field your sorting on, and this should work for you.
(note, the above uses the current version of will_paginate (3.0.2) for its syntax, but the same concept applies to older version as well using the options hash)
will_paginate
gem 将采用total_entries
参数来限制分页的条目数量。这将为您提供 3 页,每页 10 条记录。
will_paginate
gem will taketotal_entries
parameter to limit the number of entries to paginate.This gives you 3 pages of 10 records each.