非常基本的用户模型,我希望管理员用户:manage all
否则不能:索引,用户和其他一些选项,但是当我尝试阻止非管理员用户查看用户索引时,管理员用户也无权访问。
这是我的能力.rb
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new #guest user
can :manage, :all if user.role == "admin" #if user.admin? can :manage, :all
can :assign_role, User
else
can :read, :all
can :create, User
cannot :assign_role, User
cannot :index, User
can [:show, :edit, :update], User do |current_user|
user.id == current_user.id || user.role == "admin"
end
end
end
我可以做些什么来阻止所有用户被用户索引阻止?
问候
担