2013-05-05 77 views
1

我想添加管理员角色。管理员应该能够销毁并更新所有内容。
管理员是user.id = 1如何在CanCan中设置管理员角色?

我该如何在此编码?

型号/ ability.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 

回答

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 
相关问题