From 00751f02576719291822685bc97214af49887161 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Thu, 6 Oct 2011 13:32:21 +1100 Subject: [config guide] mention that to_prepare hooks are called upon every request in dev, but only once in production --- railties/guides/source/configuring.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source/configuring.textile') diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index ce1d759d5b..e56932c26c 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -461,7 +461,7 @@ 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. -- cgit v1.2.3 From 02eac2db9407ddebaca26ea6cb26d6d64a7fb24b Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Thu, 6 Oct 2011 13:32:39 +1100 Subject: [config guide] Show example of defining initialization hooks --- railties/guides/source/configuring.textile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'railties/guides/source/configuring.textile') 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: + + +module YourApp + class Application < Rails::Application + config.before_initialize do + # initialization code goes here + end + end +end + + +Alternatively, you can also do it through the +config+ method on the +Rails.application+ object: + + +Rails.application.config.before_initialize do + # initialization code goes here +end + 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. -- cgit v1.2.3