Cancan超级和管理能力不起作用



我有一个应用程序有两个角色,超级和管理员。 超级可以做所有事情,管理员应该能够做除类别之外的所有事情。我已经实现了以下内容,但它仍然允许访问管理员的类别:

def initialize(user)
user ||= User.new # guest user (not logged in)
if user.has_role? :super
can :manage, :all
elsif user.has_role? :admin
cannot :manage, :categories
can :manage, :all
end
end

如果我将其更改为以下内容,它将管理员锁定在所有内容之外。

def initialize(user)
user ||= User.new # guest user (not logged in)
if user.has_role? :super
can :manage, :all
elsif user.has_role? :admin
can :manage, :all
cannot :manage, :categories
end
end

我所有的控制器都load_and_authorize_resource,但仍然没有运气弄清楚。

规则最终以数组形式结束。

在您的第一个示例中,当您使用cannot时,该规则已从数组中删除。但是然后你定义can :manage, :all,所以删除的恢复了。

在后面的示例中,最后放置了cannot,因此删除实际上已生效。

最新更新