在我运行 ruby 2.7 的 rails 6 应用程序中,我试图使用 Zeitwerk 急切加载所有文件。这是我的 application.rb 文件的片段:
class Application < Rails::Application
config.load_defaults "6.0"
Zeitwerk::Loader.eager_load_all
# 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.
# Middlewares
config.middleware.insert 0, Rack::UTF8Sanitizer
config.middleware.use Rack::Attack
config.autoload_paths += Dir["#{config.root}/lib/**/*"]
config.autoload_paths += Dir["#{config.root}/app/models/**/*"]
config.autoload_paths += Dir["#{config.root}/app/observers/*"]
config.autoload_paths += Dir["#{config.root}/app/middleware/*"]
config.autoload_paths += Dir["#{config.root}/app/validators/**/*"]
config.autoload_paths += Dir["#{config.root}/app/**/concerns/*"]
config.autoload_paths += Dir["#{config.root}/app/operations/**/*"]
config.autoload_paths += Dir["#{config.root}/app/scrubbers/**/*"]
config.autoload_paths += Dir["#{config.root}/app/workers/**/*"]
config.paths.add "#{config.root}/app/operations/", eager_load: true
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
config.time_zone = "UTC"
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')].reject { |f| File.fnmatch("#{Rails.root.to_s}/config/locales/**/x_*.yml", f) }
config.i18n.available_locales = [:"en", :"fr", :"fr_en"]
config.i18n.default_locale = :en
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
config.assets.precompile += ["public.css", "public.js", "public_payments.js", "email.css", "pdf.css", "pronotif.css"]
config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :options]
end
end
结尾
但是,当我运行它时,我得到了这个错误:
NoMethodError: undefined method `eager_load_paths' for #<I18n::Config:0x00007fceade8c0f0>
对此的任何解决方案都会有所帮助