我在我的 Rails 应用程序中编写了自定义工具。我在这样的文件中启用它config/initializers/instrumentation.rb
:
ActiveSupport.on_load(:action_controller) do
include FooBar::ControllerRuntime
end
但这会导致我出错A copy of FooBar::ControllerRuntime has been removed from the module tree but is still active!
。我想我可以通过两种方式解决它:
- 添加路径可能是“FooBar::ControllerRuntime
is defined to
config.autoload_one_paths ” - 定义
:to_prepare
回调ActionController::Railtie
第二种解决方案如下所示:
config.to_prepare do
ActionController.include FooBar::ControllerRuntime
end
这么长的介绍引出了一个问题:哪种方式更好?首先,我禁止重新加载与我的FooBar::ControllerRuntime
. 有了第二个,我觉得搞砸是不好的ActionController::Railtie
。正确的知道ActionController::Railtie
没有定义to_prepare
,但是如果在下一个版本中会发生什么?