简单的问题,但不知何故,答案逃避了我。
在使用Zeitwerk移动到Rails 6时,我得到:
Please, check the "Autoloading and Reloading Constants" guide for solutions.
(called from <top (required)> at APP_ROOT/config/environment.rb:7)
rails aborted!
Zeitwerk::NameError: wrong constant name Enforce-calls-to-come-from-aws inferred by Module from directory
APP_ROOT/app/junkyard/enforce-calls-to-come-from-aws
Possible ways to address this:
* Tell Zeitwerk to ignore this particular directory.
* Tell Zeitwerk to ignore one of its parent directories.
* Rename the directory to comply with the naming conventions.
看起来很棒:这是一个垃圾文件夹,不应该加载,所以忽略它是完美的理由。
Zeitwerk docs at https://github.com/fxn/zeitwerk 说
tests = "#{__dir__}/**/*_test.rb"
loader.ignore(tests)
loader.setup
你如何忽略文件夹.很公平.但是如何找到loader
? Zeitwerk autoloading上的Rails指南( https://guides.rubyonrails.org/autoloading_and_reloading_constants.html )没有提到如何直接忽略文件夹,但是确实提到了在Rails.autoloaders.main
上兑现的autolostader,所以我认为
Rails.autoloaders.main.ignore("#{__dir__}/junkyard/**/*.rb")
要么
Rails.autoloaders.main.ignore("#{__dir__}/app/junkyard/**/*.rb")
会是走的方法.没有运气.我尝试将其放在application.rb
和initializers/zeitwerk.rb
中,两者都没有用.
任何想法在哪里以及如何忽略Rails中使用Zeitwerk的文件夹?
PS:是的,我知道我应该从app
中删除它,我会.但问题仍然存在.