Ruby on rails “Zeitwerk”;弃用警告:初始化自动加载常量;由于在lib文件夹中包含模块而导致

Ruby on rails “Zeitwerk”;弃用警告:初始化自动加载常量;由于在lib文件夹中包含模块而导致,ruby-on-rails,ruby-on-rails-6,deprecation-warning,Ruby On Rails,Ruby On Rails 6,Deprecation Warning,弃用警告:初始化自动加载常量AuthHelper、SemanticFormHelper、ActionText::ContentHelper和ActionText::TagHelper 自从升级到Rails 6后,我一直收到有关新Zeitwerk自动加载器的警告 这通常是由于在config/initializers文件夹中加载常量造成的,但这里的情况并非如此 AuthHelper和SemanticFormHelper由我的lib文件夹中的这两个文件拉入: module AuthorizationS

弃用警告:初始化自动加载常量AuthHelper、SemanticFormHelper、ActionText::ContentHelper和ActionText::TagHelper

自从升级到Rails 6后,我一直收到有关新Zeitwerk自动加载器的警告

这通常是由于在
config/initializers
文件夹中加载常量造成的,但这里的情况并非如此

AuthHelper
SemanticFormHelper
由我的
lib
文件夹中的这两个文件拉入:

module AuthorizationSystem
  include AuthHelper
  ...
end
初始化时,运行
lib
文件夹中的所有文件,这些文件中包含的任何内容都会触发
弃用警告

如果我删除
include
语句,警告就会消失,但应用程序会在某些页面中断,因为include是必需的

如何在我的
lib
文件夹中的文件中包含
语句而不引起警告


ActionText::ContentHelper
ActionText::TagHelper
在我的应用程序中找不到,所以我猜想这些警告来自我正在使用的一个gem。如果您有任何关于如何调试的想法,我们将不胜感激。

要查找警告的来源,您可以使用以下代码,这些代码位于
Bundler.require之前的
application.rb

ActiveSupport.on_load(:action_controller_base) do
  bc = ActiveSupport::BacktraceCleaner.new
  bc.remove_silencers!
  bc.add_silencer { |line| line.start_with?(RbConfig::CONFIG["rubylibdir"]) }
  bc.add_silencer { |line| line =~ Regexp.union(
    *(
      %w{ bootsnap railties spring activesupport actionpack zeitwerk thor rack }.
      map{|g| /\A#{g} \([\w.]+\) /}
    ),
    /\Abin\/rails/
  )}
  trace = bc.clean(caller)
  puts "Cleaned backtrace:\n\t#{trace.join("\n\t")}\n"
  puts "Most probably the cause is: #{trace.first}"
  puts "If not - uncomment `raise` at #{__FILE__}:#{__LINE__+1}"
  # raise "i can haz full backtrace"
  exit(1)
end
(来自)

ActiveSupport.on_load(:action_controller_base) do
  bc = ActiveSupport::BacktraceCleaner.new
  bc.remove_silencers!
  bc.add_silencer { |line| line.start_with?(RbConfig::CONFIG["rubylibdir"]) }
  bc.add_silencer { |line| line =~ Regexp.union(
    *(
      %w{ bootsnap railties spring activesupport actionpack zeitwerk thor rack }.
      map{|g| /\A#{g} \([\w.]+\) /}
    ),
    /\Abin\/rails/
  )}
  trace = bc.clean(caller)
  puts "Cleaned backtrace:\n\t#{trace.join("\n\t")}\n"
  puts "Most probably the cause is: #{trace.first}"
  puts "If not - uncomment `raise` at #{__FILE__}:#{__LINE__+1}"
  # raise "i can haz full backtrace"
  exit(1)
end