views:

34

answers:

2

i'm a .net guy doing some work/learning RoR. i have a handful of environment-specific settings i'd like to externalize (s3 access info). what is the way to do this? I realize the place for it is in config/environment/[environment], but i'm asking beyond that. Should it be a global constant? should i use an initializer? how do i cleanly make this data available to the consuming class?

+2  A: 

Putting the environment config in the environment files is considered the best practice. You can define these configs as constants and they will be available everywhere in your application automatically.

S3Config = { :username => "blah" }

Access the :user key by calling S3Config[:user].

Ryan Bigg
does the contents of those environment files get imported into the runtime by default? my first approach was to just define two constants in /development, but i needed a $ when consuming them (yes, i'm a ruby n00b)
kolosy
The key is :username, not :user.
Mauricio
kolosy: You don't need a global constant (a variable beginning with `$`) just capitalize the first letter (yes, it **has** to be a letter) of the variable and that will define it as a constant. The rest of the letters don't need to be capitalized.
Ryan Bigg
A: 

Have a look at the SimpleConfig Gem. It allows you to define environment variables.

It also supports environment priorities so that you can define base variables in the application.rb configuration file and override them in your environment-specific configuration files.

Simone Carletti