# Post-initializer hook?

**URL:** <https://www.ruby-forum.com/t/post-initializer-hook/153064>\
**Category:** Rails\
**Created:** [November 11, 2008, 7:07pm UTC](https://www.ruby-forum.com/t/post-initializer-hook/153064 "2008-11-11T19:07:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [November 11, 2008, 7:07pm UTC](https://www.ruby-forum.com/t/post-initializer-hook/153064/1 "2008-11-11T19:07:38Z")

</div>

Is there any callback/hook for me to add some code to be called after  
all initializers (config/initializers/\*) are called, in Rails 2?

Or should I count on initializers being run in sort order and add one  
called zzzz\_after\_all\_initializers.rb or something?

Any advice?

Jonathan

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [November 11, 2008, 7:12pm UTC](https://www.ruby-forum.com/t/post-initializer-hook/153064/2 "2008-11-11T19:12:26Z")

</div>

On 11 Nov 2008, at 18:07, Jonathan R. wrote:

> Is there any callback/hook for me to add some code to be called after  
> all initializers (config/initializers/\*) are called, in Rails 2?

config.after\_initialize do  
…  
end

Fred

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [November 11, 2008, 7:31pm UTC](https://www.ruby-forum.com/t/post-initializer-hook/153064/3 "2008-11-11T19:31:37Z")

</div>

Thanks Frederick. But, documentation and googling that led me to source  
suggests that the after\_initialize hook is called _before_  
config/initializers are.

[http://dev.rubyonrails.org/browser/tags/rel\_2-0-0\_RC1/railties/lib/initializer.rb#L340](http://dev.rubyonrails.org/browser/tags/rel_2-0-0_RC1/railties/lib/initializer.rb#L340)

114 after\_initialize  
115  
116 load\_application\_initializers

Although I guess I’m looking at 2.0RC1 there. Not familiar enough with  
navigating svn to find the latest release, is there reason to believe  
this has changed?

I guess I can monkey-patch Rails::process, with the aliasing-switcharoo  
trick, to first call the original Rails::process, and then call my own  
really\_really\_after\_initializers method?

Jonathan

Frederick C. wrote:

> On 11 Nov 2008, at 18:07, Jonathan R. wrote:
> 
> > Is there any callback/hook for me to add some code to be called after  
> > all initializers (config/initializers/\*) are called, in Rails 2?
> 
> config.after\_initialize do  
> …  
> end
> 
> Fred

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [November 11, 2008, 9:25pm UTC](https://www.ruby-forum.com/t/post-initializer-hook/153064/4 "2008-11-11T21:25:52Z")

</div>

Awesome, thank you, I’ll use 2.1 then, and count on the after\_initialize  
hook really actually being after the initializers.

Thanks for all your help, Fred.

Jonathan

Frederick C. wrote:

> On 11 Nov 2008, at 18:31, Jonathan R. wrote:
> 
> > 116 load\_application\_initializers
> > 
> > Although I guess I’m looking at 2.0RC1 there. Not familiar enough with  
> > navigating svn to find the latest release, is there reason to believe  
> > this has changed?
> 
> That was changed in 2.1 (which is what I looked at before i wrote my  
> previous reply)
> 
> > I guess I can monkey-patch Rails::process, with the aliasing-  
> > switcharoo  
> > trick, to first call the original Rails::process, and then call my own  
> > really\_really\_after\_initializers method?
> 
> sounds reasonable if you have to.
> 
> Fred

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [November 11, 2008, 9:23pm UTC](https://www.ruby-forum.com/t/post-initializer-hook/153064/5 "2008-11-11T21:23:49Z")

</div>

On 11 Nov 2008, at 18:31, Jonathan R. wrote:

> 116 load\_application\_initializers
> 
> Although I guess I’m looking at 2.0RC1 there. Not familiar enough with  
> navigating svn to find the latest release, is there reason to believe  
> this has changed?

That was changed in 2.1 (which is what I looked at before i wrote my  
previous reply)

> I guess I can monkey-patch Rails::process, with the aliasing-  
> switcharoo  
> trick, to first call the original Rails::process, and then call my own  
> really\_really\_after\_initializers method?

sounds reasonable if you have to.

Fred
