0

在我运行 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>

对此的任何解决方案都会有所帮助

4

1 回答 1

2

问题

除了您的 application.rb 状态不佳(正如@max 在您问题的第一条评论中提到的那样)之外,Rails 的问题是已知的并且已经修复

不幸的是(在撰写本文时,使用 Rails 6.0.2.2)该修复程序目前不是 public

临时解决方法

在此之前,您可以将修补过的 rake 任务复制到您的应用程序中的一个名为的文件下lib/tasks/local_zeitwerk.rake,并将第 41 行更改为:

namespace :local_zeitwerk do

然后执行检查任务

bin/rails local_zeitwerk:check
于 2020-04-04T08:48:54.473 回答