2009-12-11 40 views
1

我使用下面的代碼Will_Paginate ::收集缺少total_entries財產

@paginatedResults = WillPaginate::Collection.new(1, 5) 
@paginatedResults.replace @results[@paginatedResults.offset, 
            @paginatedResults.per_page] 

創建Will_Paginate::Collection對象,但是當我嘗試呈現使用

<%= will_paginate @paginatedResults %> 

我得到一個異常分頁

You have a nil object when you didn't expect it! 
The error occurred while evaluating nil.> 

我已將它追溯到total_entries屬性o Will_Paginate::Collections對象。該物業遺失。我不知道爲什麼。

任何想法?

回答

2

你,如果你使用新創建它,從API文檔做手工計數:

新(頁,per_page,總=無)

參數的構造函數是當前頁碼,每頁限制和條目總數。最後一個參數是可選的,因爲最好是進行延遲計數;換句話說,在使用替換方法填充集合之後有條件地進行計數。