monkeyman
monkeyman

Reputation: 247

Is environment.rb invoked on every http request?

I'm wondering what file I should use to ensure my initializing code will only be executed once when the application starts up. Is environment.rb the correct file to use or will it be invoked on every http request?

Upvotes: 1

Views: 259

Answers (2)

Mike Woodhouse
Mike Woodhouse

Reputation: 52316

Look at config/initializers for the recommended location custom startup code.

As far as possible leave environment.rb alone unless you're explicitly adding or changing items defined within the Rails::Initializer.run block.

If you want to manage custom settings across your various environments, e.g. you want production and development to have different settings for something, then the config/environments directory should be your first port of call.

Upvotes: 1

Scott
Scott

Reputation: 654

environment.rb is only loaded when the application is first started up. subsequent changes to the environment.rb file require a restart. What kind of code do you only want to execute once?

You might want to read through the Ruby on Rails guide for Configuring Rails Applications which talks about the different places to put initialization code.

Upvotes: 5

Related Questions