aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/configuring.textile
diff options
context:
space:
mode:
authorRyan Bigg <radarlistener@gmail.com>2011-10-06 13:32:39 +1100
committerRyan Bigg <radarlistener@gmail.com>2011-10-06 13:32:39 +1100
commit02eac2db9407ddebaca26ea6cb26d6d64a7fb24b (patch)
tree14547b8c3dbb400bd3ebbe2b752fe41c6864ec81 /railties/guides/source/configuring.textile
parent00751f02576719291822685bc97214af49887161 (diff)
downloadrails-02eac2db9407ddebaca26ea6cb26d6d64a7fb24b.tar.gz
rails-02eac2db9407ddebaca26ea6cb26d6d64a7fb24b.tar.bz2
rails-02eac2db9407ddebaca26ea6cb26d6d64a7fb24b.zip
[config guide] Show example of defining initialization hooks
Diffstat (limited to 'railties/guides/source/configuring.textile')
-rw-r--r--railties/guides/source/configuring.textile19
1 files changed, 19 insertions, 0 deletions
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index e56932c26c..baf944cf8d 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -467,6 +467,25 @@ Rails has 5 initialization events which can be hooked into (listed in the order
* +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.