这是一个简单的问题,但不知何故,我想不到答案。
在使用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.这看起来很棒:这是一个垃圾文件夹,永远不应该加载,所以忽略它是很有意义的。
https://github.com/fxn/zeitwerk的Zeitwerk文档说
tests = "#{__dir__}/**/*_test.rb"
loader.ignore(tests)
loader.setup忽略文件夹的方式。当然可以。但是我如何找到loader呢?Zeitwerk autoloading (https://guides.rubyonrails.org/autoloading_and_reloading_constants.html)上的Rails指南没有提到如何直接忽略文件夹,但提到了隐藏在Rails.autoloaders.main中的自动加载器,所以我认为
Rails.autoloaders.main.ignore("#{__dir__}/junkyard/**/*.rb")或
Rails.autoloaders.main.ignore("#{__dir__}/app/junkyard/**/*.rb")才是最好的选择。不走运。我试着把它放在application.rb和initializers/zeitwerk.rb中,都不管用。
有什么想法在Rails中忽略带有Zeitwerk的文件夹吗?
PS:是的,我知道我应该从app中删除它,我会这样做的。但这个问题仍然令人头疼。
发布于 2019-10-01 21:24:53
我遇到了同样的问题,结果发现它是在抱怨文件夹名称。
将此代码添加到application.rb可能会对您起作用:
Rails.autoloaders.main.ignore(Rails.root.join('app/junkyard'))
https://stackoverflow.com/questions/58125879
复制相似问题