2009-07-04 40 views
1

試圖瞭解will_paginate的paginate方法的選項:幫忙翻譯will_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_entries and count - 不明白「只有手動計數條目時才使用」?他們是否設想了一種場景,您將運行單獨的計數查詢,然後將結果作爲選項傳遞給paginate?你會這樣做的情況是什麼?

「傳遞給計數的附加選項」 - 有哪些選項可用? 「傳遞」到count方法???

回答

6

默認情況下,will_paginate使用count(來自ActiveRecord::Calculations)計算出您正在分頁的對象總數。但如果你知道的更好,或者直接計數不起作用,你可以自己計算並提供:total_entries。

:count參數用於ActiveRecord :: Calculations#count方法的額外參數,如:distinct。您可以查看完整列表的文檔。

+0

提供:total_entries似乎沒有工作了。 COUNT(*)查詢仍然在數據庫中 – 2012-11-21 06:35:57

0

當您想要在同一個列表中對不同模型進行分頁時,或者您想執行復雜查詢時,可以使用total_entries和count參數。只要你不需要它,別擔心。當遇到你無法解決的問題時,請回頭看看。