因此,将以下内容放在我的产品控制器的顶部之后:
authorize_actions_for(Product)
...这是我的 Product.rb 的顶部:
resourcify
include Authority::Abilities
...这是我的 User.rb 的顶部
rolify
include Authority::UserAbilities
我能够从 application_authorizer.rb 遵守这条规则:
def self.default(adjective, user)
user.has_role? :admin
end
换句话说,只有管理员用户才能以任何方式与产品互动。
但是,当我创建一个 product_authorizer.rb 如下
class ProductAuthorizer < ApplicationAuthorizer
def self.creatable_by?(user)
user.has_role? :admin
end
def self.updatable_by?(user)
user.has_role? :admin
end
def self.deletable_by?(user)
user.has_role? :admin
end
end
我没有看到规则得到遵守。我看到我的非管理员用户仍然无法访问产品的显示操作。鉴于上述情况,这不应该被允许吗?
我尝试将其添加到 Product.rb:
self.authorizer_name = 'StyleAuthorizer'
我还尝试在 app_app.rb 中注释掉主要规则
#def self.default(adjective, user)
# user.has_role? :admin
#end
...但仍然没有荣耀