2011-06-15 104 views
5

我使用will_paginate 「2.3.15」 爲我的Rails應用程序will_paginate - 錯誤 - 未定義的方法`TOTAL_PAGES'

在我units_controller.rb

def index 
    @units = Unit.paginate(:all ,:page => params[:page], :order => 'created_at DESC') 
end 

in my views(index) 

     <%= will_paginate(@units)%> 

but it gives error 

undefined method `total_pages' for #<ActiveRecord::Relation:0xb523dc> 

我的rails版本3.0.0 和紅寶石版本1.8.7

plz幫助

回答

4

你爲什麼加入:all? 從will_paginate wiki,你應該使用:

@units = Unit.paginate(:page => params[:page], :order => 'created_at DESC') 
+0

感謝阿德里安您的快速反應我用這個@units = Unit.paginate(:頁面=> PARAMS [:頁面]:爲了=> 'created_at DESC')仍然得到同樣的錯誤 – 2011-06-15 10:22:02

+0

我會覺得在這個版本的will_paginate中的錯誤,但我不確定。也許你可以嘗試更新到更新的版本。 – 2011-06-15 11:39:52

0

發生這種情況對我來說,當選定的一組大小是零。 (即在這種情況下,@ units.size == 0)在視圖中測試它似乎解決了這個問題。即。

<% if @units.size > 0 %> 
    <%= will_paginate @units %> 
<% end %> 
相關問題