Skip to content

Commit

Permalink
[config guide] Show example of defining initialization hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Oct 6, 2011
1 parent 00751f0 commit 02eac2d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions railties/guides/source/configuring.textile
Expand Up @@ -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.

Expand Down

0 comments on commit 02eac2d

Please sign in to comment.