簡體   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