Search code examples
configurationeager-loadingruby-on-rails-5

Rails 5 Beta: Put eager_load_paths config on initializer throw frozen array exception


I followed commented guidelines in config/application.rb which is

   # Settings in config/environments/* take precedence over those specified here.
   # Application configuration should go into files in config/initializers
   # -- all .rb files in that directory are automatically loaded.

But when i added Rails.application.config.eager_load_paths << Rails.root.join('lib') in config/initializers/eager_load.rb.

It throws <top (required)>': can't modify frozen Array (RuntimeError)

Yes it is working if i put it inside config/application.rb.

I want to know why is it not working on initializer and how to make it work using the convention ?


Solution

  • Try this instead in config/initializers/xxx.rb:

    Rails.application.config.eager_load_paths += [Rails.root.join('lib')]