在Rails 6中的Zeitwerk模式中,这些代码中有任何一个是折旧的吗?
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2
# config/application.rb
config.i18n.load_path += Dir[Rails.root.join("config", "locales", "**", "*.{rb,yml}")]
config.i18n.fallbacks = true
# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.
config.autoload_paths += ["#{config.root}/app/queries/"]
# https://gist.github.com/maxim/6503591 (should remove this and fix)
config.eager_load_paths << Rails.root.join("lib")我读到自动加载正在被删除,到目前为止它还没有引起任何问题,而是想删除不推荐的代码。如果它被折旧,我如何加载我的代码?
发布于 2020-01-13 15:36:09
这里没有什么是不推荐的,但是值得一提的是来自文档
可以在config/application.rb中通过变异config.autoload_paths来扩展自动加载路径数组,但现在不鼓励这样做。
Rails 5+阻止了手动扩展config.autoload_paths的使用,因为它可能会在生产环境中造成问题。讨论可以追溯到2013年,你可以在这里上读到。
在Rails 5+中,应用程序/下的所有目录默认都是自动加载的。如果您想遵循Rails的建议,您应该删除这一行
config.autoload_paths += ["#{config.root}/app/queries/"]并将查询目录移到"#{Rails.root}/app“文件夹下。
https://stackoverflow.com/questions/59505226
复制相似问题