1
我正在使用Cancan accessible_by
來檢索ActiveRecord :: Relation結果(下面的示例代碼)。在撥打電話accessible_by
期間有什麼方法可以訂購結果嗎?是否有任何方法來訂購Cancan的結果accessible_by調用
更新:Srdjan的是正確的。 @attributes
已被設置爲使用accessible_by
。我已更新示例以顯示按用戶的登錄進行排序。 Attribute
與User
有belongs_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