2012-04-24 89 views
2

請分頁(3.0.3)不適用於繼承的資源(1.3.1)。在我的控制器:will_paginate和inherited_resources不能一起工作

protected 
def collection 
    @posts ||= end_of_association_chain.paginate(:page => params[:page]) 
end 

我說需要我的初始化「will_paginate /陣列」,但這並沒有解決問題。我怎樣才能工作將分頁和繼承資源放在一起?在我的意見,我得到錯誤

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

回答

3

這是怎樣的一個長鏡頭,但我遇到了這個問題,事實證明這是慘慘,我使用的另一顆寶石。這是我偶然發現的第一件事情,所以我認爲它可能有助於某一天。

退房:https://github.com/ryanb/cancan/wiki/Inherited-Resources

的調用load_and_authorize_resource載荷收集所以有條件分配的右側永遠不會在collection方法運行。上面鏈接中描述的修復程序是跳過收集操作的授權,並在collection方法中明確進行檢查。

skip_load_and_authorize_resource :only => :index 

protected 

def collection 
    @posts ||= end_of_association_chain.accessible_by(current_ability).paginate(:page => params[:page]) 
end 

我希望能幫到別人。