2011-03-23 20 views
1

我正在使用Cancan accessible_by來檢索ActiveRecord :: Relation結果(下面的示例代碼)。在撥打電話accessible_by期間有什麼方法可以訂購結果嗎?是否有任何方法來訂購Cancan的結果accessible_by調用

更新:Srdjan的是正確的。 @attributes已被設置爲使用accessible_by。我已更新示例以顯示按用戶的登錄進行排序。 AttributeUserbelongs_to的關係。

class AttributesController < ApplicationController 
    load_and_authorize_resource 

    def index 
    @attributes = @attributes.includes(:user).order("#{User.table_name}.login") 
    end 

    # GET /attribute/1 
    # GET /attribute/1.xml 
    def show 
    respond_to do |format| 
     format.html # show.html.erb 
     format.xml { render :xml => @attribute } 
    end 
    end 
end 

回答

3

從馬的嘴裏就像它一樣。

@articles = Article.accessible_by(current_ability, :update)
這是爲了其他範圍和分頁可以被鏈接到它的活動記錄範圍。

來源:https://github.com/ryanb/cancan/wiki/Fetching-Records

此外,在該頁面的頂部,你會注意到,作爲慘慘1.4,這是自動,當你調用load_resource完成。你在那個版本?