Configuration load order in Rails

19.01.2015 - Pascal Betz

Ever wondered what the load order of the various configuration files of Rails is?

In Rails the (more or less) common places to configure your app are:

  • application.rb
  • config/environments/*.rb
  • config/initializers/*.rb
  • after_initialize callbacks (in application.rb or in environment specific files)

Since there is multiple points where you can add the configuration the order in which those configurations are applied is important. E.g. it might happen that you set a value in one place and it gets reverted from another config file. This is the order that get’s applied, tested in Rails 4.2

  1. application.rb
  2. environment specific config file in config/environments/*.rb
  3. initializers, they are loaded in alphabetical order
  4. after_initialize callbacks, in the order they have been added