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")
我读到自动加载正在被删除,到目前为止它还没有引起问题,但想删除已弃用的代码。如果折旧,我该如何加载我的代码?
这里的任何内容都没有被弃用,但是值得一提的是文档 https://guides.rubyonrails.org/autoloading_and_reloading_constants.html:
自动加载路径数组可以通过改变 config/application.rb 中的 config.autoload_paths 来扩展,但现在不鼓励这样做。
Rails 5+ 不鼓励使用手动扩展配置自动加载路径因为它可能会在您的生产环境中引起潜在问题。该讨论可以追溯到 2013 年,您可以阅读相关内容here https://github.com/rails/rails/issues/13142.
从 Rails 5+ 下的所有目录app/默认情况下自动加载。如果您想遵循 Rails 建议,则应删除此行
config.autoload_paths += ["#{config.root}/app/queries/"]
并将您的查询目录移至“#{Rails.root}/应用程序” folder.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)