ruby on rails - Restricting admin from destroying own account using cancan -
here snippet of code ability class
if user.admin? can :manage, :all can :destroy, :all if != current_user
i sure can figure out trying here. realize destroy included in manage , repeating myself there. suggestions?
edit yjerem's answer correct 1 , changed fit code. looks like.
if user.admin? can :manage, :all cannot :destroy, user, :id => user.id
as yjerem said, in cancan, ability precedence states ability defined lower down trump ones on them admin can manage except defined under using code above.
read ability precedence, there's example there you!
basically want cannot
method:
if user.admin? can :manage, :all cannot :destroy, user, :id => current_user.id
because cannot
rule below more general one, overrides it.
Comments
Post a Comment