Take the 2-minute tour ×

I tried:

after_initialize do

But: (documentation)


I need routing and logger in my code

Any ideas?

share|improve this question
could you state your problem more explicitly. –  Bhushan Lodha Dec 17 '11 at 9:51
I want on_server_start event. –  user1103291 Dec 17 '11 at 10:16
Why would you want that? What do you want to do? Explain your problem and maybe there is a better solution than an "on_server_start" event. –  Maurício Linhares Dec 17 '11 at 11:23
add comment

2 Answers

See section 3.1 from http://guides.rubyonrails.org/configuring.html

I beleive you would put this code in config/application.rb

config.after_initialize do
    # ....

# config.after_initialize takes a block which will be run after Rails has finished initializing the application. 
# That includes the initialization of the framework itself

Also http://guides.rubyonrails.org/initialization.html

share|improve this answer
This also runs when the Rails console (rails c) is invoked. –  Vortico Feb 9 at 4:17
add comment

Another option is to create a custom initializer. It's just a ruby file that lives under config/initializers/ and is executed exactly "on_server_start" event :)

share|improve this answer
add comment

Your Answer


