我正在使用 Cancanaccessible_by
来检索 ActiveRecord::Relation 结果(下面的示例代码)。有没有办法在accessible_by
通话期间订购结果?
更新:Srdjan 是正确的。@attributes
已经使用accessible_by
. 我更新了示例以显示按用户登录的排序。Attribute
与 有belongs_to
关系User
。
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