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?
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.
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.