ruby-on-rails - Rails 中的 Pundit::AuthorizationNotPerformedError

标签 ruby-on-rails pundit

screenshot

什么可能导致 verify_authorized 方法中出现此错误以及如何解决?

最佳答案

Pundit 向您的 Controller 添加了一个名为 verify_authorized 的方法,以确保在您的 Controller 操作中的某处调用了 authorize 方法。您可能设置了一个调用 verify_authorized ( https://github.com/elabs/pundit#ensuring-policies-and-scopes-are-used ) 的 after_action。确保通过 Controller 操作在每个可能的执行路径中调用 authorize

或者,如果您不想授权该特定操作,您可以跳过它:

class PagesControler < ApplicationController
  include Pundit
  after_action :verify_authorized, except: [:home]

  ...
end

或者如果您在继承的 Controller 中设置after_action:

class ApplicationController < ActionController::Base
  include Pundit
  after_action :verify_authorized

  ...
end

class PagesControler < ApplicationController
  skip_after_action :verify_authorized, only: [:home]

  ...
end

关于ruby-on-rails - Rails 中的 Pundit::AuthorizationNotPerformedError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35071428/

相关文章:

ruby-on-rails - Heroku 水平与垂直缩放和 1x 与 2x dynos

ruby-on-rails - 将 Pundit 用于所有访问权限 "super_admin"角色

ruby-on-rails - 专家上下文访问

ruby-on-rails - 未定义的方法 'authorize' 与 Pundit

css - rails 4 : How to exclude a CSS file from a specific view?

ruby-on-rails - 在 rspec 的 Controller 测试中使用 rails 的 "post",在路由上使用范围和协议(protocol)

ruby-on-rails - 你如何通过 Clearance 和 Pundit 邀请另一个用户到 "team"或 "account"或 "project"?

ruby-on-rails - 如何使用 Pundit 限制对用户资源索引操作的授权?我认为答案不是范围

ruby-on-rails - Ruby 通用捕获所有错误

ruby-on-rails - rails 7 : Loading all Stimulus controllers