I\'m trying to learn the life cycle of a rails application. When is application_controller.rb run? Is it just once every time it\'s changed, or on every request?
I want
With a little effort, you can follow it through yourself, which will probably be more useful.
Start from 'ruby script/server'. In my (2.1) application, that look for a file named "server" in the "script" directory. It contains this:
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'
So it requires boot.rb, which defines a whole lot of stuff and then calls Rails.boot!
which more or less runs any pre-initialization you've defined and then requires environment
, which does another level of bootstrapping. By that time it's starting to get complicated: I'd recommend a large-ish sheet of paper...
And so on.
Alternatively, you may be able to hack Kernel#require
to log when a file is being required in - I haven't tried it myself (and the method may be overridden elsewhere) but it could work...
application_controller isn't exactly "run" at all - it's a parent class for your other controllers, so its content, if required and not overridden becomes available when the inheriting controller is loaded. You'd generally use it to provide common functionality across all your controllers.