仅允许使用CanCanCan创建受限用户

时间:2016-12-07 10:01:17

标签: ruby-on-rails ruby cancan cancancan

我希望管理员用户无法创建具有超级管理员角色的用户,但仍然可以创建其他管理员和常规用户。我该如何做到这一点?这是我的Ability.rb:

class Ability
  include CanCan::Ability

  def initialize(user)
    if user.super_admin?
      can :manage, :all
    elsif user.admin?
      can :manage, [Article, Comment]
      can [:destroy, :update], User, :role_id => 2 # If Admin
      can [:destroy, :update], User, :role_id => 3 # If User
      can :read, User
      can :create, User
    elsif user.user_regular?
      #cannot :read, ActiveAdmin::Page, :name => "Dashboard"
      #can :manage, :all

    end
  end
end

1 个答案:

答案 0 :(得分:0)

cannotadmin中使用cannot :creat, User, :role_id => 1 # let 1 is super admin role id。您可以获得有关合并能力at here

的更多信息