Rails boot sequence
As I was having issues with a misbehaving gem, I needed to demystify Rails’ boot sequence for myself. As a (brief) web search also didn’t return many visual resources, I made a summary of Xavier Noria’s talk.
To summarize in words:
- Define load paths for deps (Bundle.setup)
- Load rails/all (railties of Rails components)
- Load gem deps (Bundle.require)
- Define the
Application
class - Define assorted paths (autoload etc.) #Rails.application.initialize!
- Load config/environments/#{Rails.env}.rb
- Load initializers in config/initializers
- Eager load application (if nil). Happens by default in
production
mode. - Load
config/routes.rb
- Run command hooks (if needed).