My default environment.rb is overflowing, and i would like to have a separate file that works exactly the same way. How can I do so?
+1
A:
Rails actually uses eval
to load the special environment files such as config/environments/development.rb. This is the code it uses:
eval(IO.read(configuration.environment_path), binding, configuration.environment_path)
You could define a method such as load_more_environment
like this:
def load_more_environment(path)
eval(IO.read(path), binding, path)
end
The first argument to eval
is just the code you want to load and it will be executed within the current binding
. The third argument will be used to report syntax errors in the file.
Ryan Bigg
2010-08-20 20:31:45
This is fascinating. Thanks! =)
ming yeow
2010-08-21 02:52:46
+4
A:
You're likely adding things to the environment file that should be in an initializer. Check the config/initializers directory for some examples of what to put in there. That should allow you to break things up and make everything more organized.
Beerlington
2010-08-20 20:32:48
Interesting! what should be in the initializer and what should be in environment? What is the "proper rails" way?
ming yeow
2010-08-21 02:36:59
I usually use the environment.rb file for settings that are already in there such as `config.gem ...`. Anything else that's not specific to an environment goes in an initializer. http://ryandaigle.com/articles/2007/2/23/what-s-new-in-edge-rails-stop-littering-your-evnrionment-rb-with-custom-initializations
Beerlington
2010-08-22 19:27:56