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
- railties/exe/rails
- railties/lib/rails/app_loader.rb
- bin/rails
- config/boot.rb
- rails/commands.rb
- rails/command.rb
- actionpack/lib/action_dispatch.rb
- rails/commands/server/server_command.rb
- Rack: lib/rack/server.rb
- config/application
- Rails::Server#start
- config/environment.rb
- config/application.rb
Load
- railties/lib/rails/all.rb
- Back to config/environment.rb
- railties/lib/rails/application.rb
- 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:
- bin/rails
- config/boot.rb
- rails/commands.rb
- actionpack/lib/action_dispatch.rb
- rails/commands/server.rb
- Rack: lib/rack/server.rb
- config/application
- Rails::Server#start
- config/environment.rb
- config/application.rb
- railties/lib/rails/all.rb
- Back to config/environment.rb
- railties/lib/rails/application.rb
- 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:
- bin/rails railties/lib/rails/cli.rb script/rails config/boot.rb
- rails/commands.rb actionpack/lib/action_dispatch.rb
- activesupport/lib/active_support.rb
- activesupport/lib/active_support/lazy_load_hooks.rb
- activesupport/lib/active_support/inflector/methods.rb
- actionpack/lib/action_dispatch.rb cont’d. rails/commands/server.rb
- Rack: lib/rack/server.rb Rails::Server#start config/environment.rb
- config/application.rb Loading Rails railties/lib/rails/all.rb
- railties/lib/rails.rb railties/lib/rails/ruby_version_check.rb
- active_support/core_ext/kernel/reporting.rb
- active_support/core_ext/logger.rb railties/lib/rails/application.rb
- active_support/file_update_checker.rb railties/lib/rails/plugin.rb
- railties/lib/rails/engine.rb railties/lib/rails/railtie.rb
- railties/lib/rails/initializable.rb
- railties/lib/rails/configuration.rb
- activesupport/lib/active_support/deprecation.rb
- activesupport/lib/active_support/deprecation/behaviors.rb
- activesupport/lib/active_support/notifications.rb
- activesupport/core_ext/array/wrap
- activesupport/lib/active_support/deprecation/reporting.rb
- activesupport/lib/active_support/deprecation/method_wrappers.rb
- activesupport/lib/active_support/deprecation/proxy_wrappers.rb
- active_support/ordered_options railties/lib/rails/paths.rb
- railties/lib/rails/rack.rb
- activesupport/lib/active_support/inflector.rb
- active_support/inflections
- activesupport/lib/active_support/inflector/transliterate.rb Back to
- railties/lib/rails/railtie.rb railties/lib/rails/engine/railties.rb
- Back to railties/lib/rails/engine.rb Back to
- railties/lib/rails/plugin.rb Back to
- railties/lib/rails/application.rb railties/lib/rails/version.rb
- activesupport/lib/active_support/railtie.rb
- activesupport/lib/active_support/i18n_railtie.rb
- railties/lib/rails/railtie/configuration.rb Back to
- activesupport/lib/active_support/i18n_railtie.rb Back to
- activesupport/lib/active_support/railtie.rb
- activesupport/lib/action_dispatch/railtie.rb
- activesupport/lib/action_dispatch.rb activemodel/lib/active_model.rb
- activesupport/lib/active_support/i18n.rb Back to
- activesupport/lib/action_dispatch.rb Back to
- activesupport/lib/action_dispatch/railtie.rb Back to
- railties/lib/rails.rb Back to railties/lib/rails/all.rb
- activerecord/lib/active_record/railtie.rb
- activerecord/lib/active_record.rb Back to
- activerecord/lib/active_record/railtie.rb
- actionpack/lib/action_controller/railtie.rb
- 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.
- config/preinitializer.rb
- config/environment.rb
- config/environments/#{RAILS_ENV}.rb
- plugin initialization
- gem initialization
- config/initializer/*.rb
- all after_initialize blocks, in the order they were defined in (so same order as above)
- 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.