1

我想为此添加管理员角色。管理员应该能够销毁和更新所有内容。
管理员是user.id = 1

我怎样才能在这个中编码?

模型/能力.rb

if user
    .....
    can :read, :all 
    can [:create, :destroy], Comment, {:user_id => user.id}
    can [:destroy], Comment, {:commentable_id => user.id, :commentable_type => user.class.name}
    can [:create, :update], Community, {:user_id => user.id}
    .....
else
    can :read, :all 
end
4

1 回答 1

0

你是如此接近它甚至都不好笑。

你正在寻找can :manage, :all

if user
  if user.admin? # or user.id == 1
    can :manage, :all
  else
    .....
    can :read, :all 
    can [:create, :destroy], Comment, {:user_id => user.id}
    can [:destroy], Comment, {:commentable_id => user.id, :commentable_type => user.class.name}
    can [:create, :update], Community, {:user_id => user.id}
    .....
  else
    can :read, :all 
end
于 2013-05-05T15:32:37.780 回答