【发布时间】:2021-07-12 12:05:56
【问题描述】:
作为我一直在做的迁移工作的一部分,我遇到了 pundit 的猴子补丁初始化。我大部分都理解它,但有一部分导致我出错:
module Pundit
class << self
def authorize; raise 'DoNotUseThisMethod'; end
def authorize!; raise 'DoNotUseThisMethod'; end
end
included do
if respond_to?(:rescue_from)
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
end
if respond_to?(:helper_method)
helper_method :authorize
helper_method :can?
end
end
protected
...
# authorize, authorize! and other methods defined
启动服务器时出错:
/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.11.3/lib/active_support/concern.rb:126:in `included': Cannot define multiple 'included' blocks for a Concern (ActiveSupport::Concern::MultipleIncludedBlocks)
我尝试将此模块移动到concerns 文件夹,但如果我这样做,authorize 方法将不会被调用。
Pundit 模块我包含在 ApplicationController 中。
有什么想法吗?我知道我之前遇到过这个错误,我什至在这里描述了它,但这次我没有像其他文件一样命名空间。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 pundit