In what order are the config files loaded for Rails?

Rails 6.0

Updated Nov 2019: Initialization Process and Configuration

Same as Rails 5.2

Rails 5.2

Updated Nov 2019:Initialization Process Configuration

Launch

  1. railties/exe/rails
  2. railties/lib/rails/app_loader.rb
  3. bin/rails
  4. config/boot.rb
  5. rails/commands.rb
  6. rails/command.rb
  7. actionpack/lib/action_dispatch.rb
  8. rails/commands/server/server_command.rb
  9. Rack: lib/rack/server.rb
  10. config/application
  11. Rails::Server#start
  12. config/environment.rb
  13. config/application.rb

Load

  1. railties/lib/rails/all.rb
  2. Back to config/environment.rb
  3. railties/lib/rails/application.rb
  4. Rack: lib/rack/server.rb

Rails 4.2

Updated Sep 2013: For Rails 4 it appears to have changed again. There is now a Rails-4 Guide on The Rails Initialization Process. You'll notice that this list is much shorter than the one for Rails 3. I'm not sure if they removed some of the depth or what... Haven't had the time to go over it all:

  1. bin/rails
  2. config/boot.rb
  3. rails/commands.rb
  4. actionpack/lib/action_dispatch.rb
  5. rails/commands/server.rb
  6. Rack: lib/rack/server.rb
  7. config/application
  8. Rails::Server#start
  9. config/environment.rb
  10. config/application.rb
  11. railties/lib/rails/all.rb
  12. Back to config/environment.rb
  13. railties/lib/rails/application.rb
  14. Rack: lib/rack/server.rb

For more detailed information on how to configure some of these files see the Rails-4 Guide on Configuring Rails Applications


Rails 3.2

Updated Sep 2013: For Rails 3 it appears to have changed a lot. There is now a Rails-3 Guide on The Rails Initialization Process:

  1. bin/rails railties/lib/rails/cli.rb script/rails config/boot.rb
  2. rails/commands.rb actionpack/lib/action_dispatch.rb
  3. activesupport/lib/active_support.rb
  4. activesupport/lib/active_support/lazy_load_hooks.rb
  5. activesupport/lib/active_support/inflector/methods.rb
  6. actionpack/lib/action_dispatch.rb cont’d. rails/commands/server.rb
  7. Rack: lib/rack/server.rb Rails::Server#start config/environment.rb
  8. config/application.rb Loading Rails railties/lib/rails/all.rb
  9. railties/lib/rails.rb railties/lib/rails/ruby_version_check.rb
  10. active_support/core_ext/kernel/reporting.rb
  11. active_support/core_ext/logger.rb railties/lib/rails/application.rb
  12. active_support/file_update_checker.rb railties/lib/rails/plugin.rb
  13. railties/lib/rails/engine.rb railties/lib/rails/railtie.rb
  14. railties/lib/rails/initializable.rb
  15. railties/lib/rails/configuration.rb
  16. activesupport/lib/active_support/deprecation.rb
  17. activesupport/lib/active_support/deprecation/behaviors.rb
  18. activesupport/lib/active_support/notifications.rb
  19. activesupport/core_ext/array/wrap
  20. activesupport/lib/active_support/deprecation/reporting.rb
  21. activesupport/lib/active_support/deprecation/method_wrappers.rb
  22. activesupport/lib/active_support/deprecation/proxy_wrappers.rb
  23. active_support/ordered_options railties/lib/rails/paths.rb
  24. railties/lib/rails/rack.rb
  25. activesupport/lib/active_support/inflector.rb
  26. active_support/inflections
  27. activesupport/lib/active_support/inflector/transliterate.rb Back to
  28. railties/lib/rails/railtie.rb railties/lib/rails/engine/railties.rb
  29. Back to railties/lib/rails/engine.rb Back to
  30. railties/lib/rails/plugin.rb Back to
  31. railties/lib/rails/application.rb railties/lib/rails/version.rb
  32. activesupport/lib/active_support/railtie.rb
  33. activesupport/lib/active_support/i18n_railtie.rb
  34. railties/lib/rails/railtie/configuration.rb Back to
  35. activesupport/lib/active_support/i18n_railtie.rb Back to
  36. activesupport/lib/active_support/railtie.rb
  37. activesupport/lib/action_dispatch/railtie.rb
  38. activesupport/lib/action_dispatch.rb activemodel/lib/active_model.rb
  39. activesupport/lib/active_support/i18n.rb Back to
  40. activesupport/lib/action_dispatch.rb Back to
  41. activesupport/lib/action_dispatch/railtie.rb Back to
  42. railties/lib/rails.rb Back to railties/lib/rails/all.rb
  43. activerecord/lib/active_record/railtie.rb
  44. activerecord/lib/active_record.rb Back to
  45. activerecord/lib/active_record/railtie.rb
  46. actionpack/lib/action_controller/railtie.rb
  47. actionpack/lib/action_view.rb

For more detailed information on how to configure some of these files see the Rails-3 Guide on Configuring Rails Applications


Rails 2.3

Originally (Dec 2011), I stumbled across a blog post that had an awesome explanation of How the Initialization Process Worked for Rails 2.

  1. config/preinitializer.rb
  2. config/environment.rb
  3. config/environments/#{RAILS_ENV}.rb
  4. plugin initialization
  5. gem initialization
  6. config/initializer/*.rb
  7. all after_initialize blocks, in the order they were defined in (so same order as above)
  8. any junk left below the Rails::Initializer.run call/block in environment.rb

For more detailed information on how to configure some of these files see the Rails-2 Guide on Configuring Rails Applications


This answer is used to supplement the accepted answer, the accepted answer didnt mention when development.rb and other init files load.

In ruby 2.0, I insert following code in bin/rails, then run 'bin/rails s' to view the loading order of local application files. In this example, my project name is bole_api.

files = []
tp = TracePoint.new(:line) do |tp|
  if tp.path =~ /bole_api/
    unless files.include? tp.path
    puts "#{tp.path}".inspect
    files.push(tp.path)
    end
  end
end
tp.enable

and my local result is

"/home/leijing/studio/bole_api/bin/rails"
"/home/leijing/studio/bole_api/config/boot.rb"
"/home/leijing/studio/bole_api/Gemfile"
"/home/leijing/studio/bole_api/config/application.rb"
=> Booting WEBrick
=> Rails 4.1.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
"/home/leijing/studio/bole_api/config.ru"
"/home/leijing/studio/bole_api/config/environment.rb"
"/home/leijing/studio/bole_api/config/environments/development.rb"
"/home/leijing/studio/bole_api/config/initializers/carrierwave.rb"
"/home/leijing/studio/bole_api/config/initializers/cookies_serializer.rb"
"/home/leijing/studio/bole_api/config/initializers/filter_parameter_logging.rb"
"/home/leijing/studio/bole_api/config/initializers/rabl_init.rb"
"/home/leijing/studio/bole_api/config/initializers/session_store.rb"
"/home/leijing/studio/bole_api/config/initializers/wrap_parameters.rb"
"/home/leijing/studio/bole_api/config/routes.rb"
"/home/leijing/studio/bole_api/app/api/bole_app_api.rb"
"/home/leijing/studio/bole_api/app/api/home_api.rb"
"/home/leijing/studio/bole_api/app/api/video_api.rb"
[2014-06-27 11:06:57] INFO  WEBrick 1.3.1
[2014-06-27 11:06:57] INFO  ruby 2.1.0 (2013-12-25) [x86_64-linux]
[2014-06-27 11:06:57] INFO  WEBrick::HTTPServer#start: pid=30157 port=3000

From the above output, you can get a view of the order of how local files loaded. And combine the conclusion of http://edgeguides.rubyonrails.org/initialization.html, you can get a view of whole initialize process.