aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/configuring.textile
diff options
context:
space:
mode:
authorManuel Menezes de Sequeira <MMSequeira@gmail.com>2011-10-06 21:31:26 +0100
committerManuel Menezes de Sequeira <MMSequeira@gmail.com>2011-10-06 21:31:26 +0100
commita17e5e24624d27467e3d7a52ff83c00140890557 (patch)
tree96ea19c3b0b23f0782910384c476d2662471ed73 /railties/guides/source/configuring.textile
parent29bf193cadae8c0b01f565caed75eb285ba8c958 (diff)
parent545ddbdbc5b61716fb884488206567a130902f0a (diff)
downloadrails-a17e5e24624d27467e3d7a52ff83c00140890557.tar.gz
rails-a17e5e24624d27467e3d7a52ff83c00140890557.tar.bz2
rails-a17e5e24624d27467e3d7a52ff83c00140890557.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'railties/guides/source/configuring.textile')
-rw-r--r--railties/guides/source/configuring.textile21
1 files changed, 20 insertions, 1 deletions
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index ce1d759d5b..baf944cf8d 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -461,12 +461,31 @@ Rails has 5 initialization events which can be hooked into (listed in the order
* +before_initialize+: This is run directly before the initialization process of the application occurs with the +:bootstrap_hook+ initializer near the beginning of the Rails initialization process.
-* +to_prepare+: Run after the initializers are ran for all Railties (including the application itself), but before eager loading and the middleware stack is built.
+* +to_prepare+: Run after the initializers are ran for all Railties (including the application itself), but before eager loading and the middleware stack is built. More importantly, will run upon every request in +development+, but only once (during boot-up) in +production+ and +test+.
* +before_eager_load+: This is run directly before eager loading occurs, which is the default behaviour for the _production_ environment and not for the +development+ environment.
* +after_initialize+: Run directly after the initialization of the application, but before the application initializers are run.
+To define an event for these hooks, use the block syntax within a +Rails::Aplication+, +Rails::Railtie+ or +Rails::Engine+ subclass:
+
+<ruby>
+module YourApp
+ class Application < Rails::Application
+ config.before_initialize do
+ # initialization code goes here
+ end
+ end
+end
+</ruby>
+
+Alternatively, you can also do it through the +config+ method on the +Rails.application+ object:
+
+<ruby>
+Rails.application.config.before_initialize do
+ # initialization code goes here
+end
+</ruby>
WARNING: Some parts of your application, notably observers and routing, are not yet set up at the point where the +after_initialize+ block is called.