views:

71

answers:

3

I want to store a path for a special directory used by my Rails application. Should I store that in environment.rb, or is there another place this is meant to go?

THE_DIRECTORY_PATH = '/path/to/directory'

Let's assume my controllers + models or libraries in /lib need access as well.

+1  A: 

If controllers need access to it, then a better place would be the ApplicationController.

Anurag
It may be that only they need access. Not sure at this point. But if my controllers + models or libraries in /lib need access as well, would environment.rb be the place?
Chad Johnson
something about environment.rb just doesn't feel right, unless you have different paths for different environments. also, take a look at initializers in this configuration guide - http://guides.rails.info/configuring.html#using-initializers
Anurag
I kinda hate constants like this. You really *have* to define them in each environment - almost certainly you'll want a different value for one of them in production.
Jonathan Julian
+1  A: 

How about storing it in a YAML configuration file that gets loaded by an initializer? This Railscast has the details.

John Topley
Hmm, not bad. I'll look into this...
Chad Johnson
+1  A: 

Use a robust YAML-file approach that allows per-environment settings. Try app_config, which has loads of great features, including referring syntax like AppConfig.the_directory_path.

Jonathan Julian
AppConfig looks interesting. I hate global constants floating around, so encapsulating things like that would be awesome.
Chad Johnson