EDIT持つ異なるユーザに同じ文字列を生成しません:CanCanCanのバージョン1.12のとおりCanCanCan
のために改訂されました( CanCanのコミュニティ継続)、Ability.new(user).permissions
は、指定されたユーザーのすべての権限を持つハッシュを返します。
前の回答(カンカン):
これは少し複雑かもしれません...しかし、ここではそれが行く..
あなたはカンカンで必要とされる能力モデルに指定されたユーザーを渡す場合は、あなたはこれらのルールはでされたモデルをお知りになりたい場合は
...
>> u=User.new(:role=>"admin")
>> a=Ability.new(u)
>> a.instance_variable_get("@rules").collect{
|rule| rule.instance_variable_get("@actions").to_s
}
=> ["read", "manage", "update"]
をinstance_variable_getを使用して、そのユーザの役割の定義にアクセスして、そこから好きな文字列値にそれを打破することができます時flicted、あなたはここで
は、私は私が自分の能力を送信したい
Ability:0x5b41dba @rules=[
#<CanCan::Rule:0xc114739
@actions=[:read],
@base_behavior=true,
@conditions={},
@match_all=false,
@block=nil,
@subjects=[
User(role: string)]>,
#<CanCan::Rule:0x7ec40b92
@actions=[:manage],
@base_behavior=true,
@conditions={},
@match_all=false,
@block=nil,
@subjects=[
Encounter(id: integer)]>,
#<CanCan::Rule:0x55bf110c
@actions=[:update],
@base_behavior=true,
@conditions={:id=>4},
@match_all=false,
@block=nil,
@subjects=[
User(role: string)]>
]
出典
2012-04-13 19:20:21
RGB
は、その恵みを逃した:
そして、ここでは、缶()メソッドを実装して、私のBACKBONE.JSモデルです! : – RGB