What if you need to change authorization based on a model’s attributes? You can do so by passing a hash of conditions as the last argument to can. For example, if you want to only allow one to access projects which he owns you can set the :user_id option.
我建议使用
CanCan进行授权.
你的能力模型看起来像
can :manage, :isbn do |isbn|
isbn.account == current_user.account
end
What if you need to change authorization based on a model’s attributes? You can do so by passing a hash of conditions as the last argument to can. For example, if you want to only allow one to access projects which he owns you can set the :user_id option.
我建议使用
CanCan进行授权.
你的能力模型看起来像
can :manage, :isbn do |isbn|
isbn.account == current_user.account
end