我安装了Activeadmin和Pundit gems。
在application_controller.rb中添加了'include Pundit‘。
定义的package_policy.rb
class PackagePolicy < ApplicationPolicy
def update?
user.admin?
end
endapplication_policy.rb:
class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
@user = user
@record = record
end
def index?
false
end
def show?
false
end
def create?
false
end
def new?
create?
end
def update?
false
end
def edit?
update?
end
def destroy?
false
end
def scope
Pundit.policy_scope!(user, record.class)
end
class Scope
attr_reader :user, :scope
def initialize(user, scope)
@user = user
@scope = scope
end
def resolve
scope
end
end
end然后我就会得到
page isn’t redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete在我的浏览器里。也许,它是无限循环或类似的东西。
我有一些不同的package_policy.rb配置,但添加application_policy.rb后-在尝试登录Activeadmin面板后,结果总是在浏览器中出现错误。
发布于 2020-05-27 17:24:06
我允许对ApplicationPolicy中的所有方法执行所有操作。
在我为我的资源创建了具有所需权限的新策略之后。
在ApplicationPolicy中:
...
def index?
true
end
def show?
true
end
def create?
true
end
def new?
create?
end
def update?
true
end
def edit?
update?
end
def destroy?
true
end
...在任何其他策略中,例如:
...
def index?
user.admin?
end
def show?
user.admin?
end
def create?
user.admin?
end
def new?
create?
end
def update?
user.admin?
end
def edit?
update?
end
def destroy?
user.admin?
end
...https://stackoverflow.com/questions/61824012
复制相似问题