繁体   English   中英

will_paginate宝石不起作用

[英]will_paginate gem not working

我遇到了will_paginate的问题,表达起来非常简单:

> Story.paginate(page: 1, per_page: 10).count
=> 20

显然,这个数字应该是10,而不是20。

我在某种程度上做错了什么? 看起来似乎没有太大的错误空间,但显然有些事情是不对的。 我错过了什么?

你想要Story.paginate(page: 1, per_page:10).size ,不count Count实际上将返回查询生成的记录总数。

因为will_paginate gem会覆盖count方法

def count(*args)
  if limit_value
    excluded = [:order, :limit, :offset, :reorder]
    excluded << :includes unless eager_loading?
    rel = self.except(*excluded)
    column_name = (select_for_count(rel) || :all)
    rel.count(column_name)
  else
    super(*args)
  end
end

它将排除order, limit, offset and reorder 链接到代码

您应该使用sizetotal_entries

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM