How To Add Extra Application Configuration

Hello Everyone,

I would like to add a few configurable values to my application but I am not sure how to do it. I have looked through a few Rails books and tried Google but without any luck.

I notice that the final line of config/environment.rb tantalisingly reads:

   # Include your application configuration below

Unfortunately I cannot find any information on how (what format) to add in my configuration and how then to access it from my code. Could anybody please point me in the right direction?

Any help would be much appreciated.

Thanks and regards,
Andy Stewart

This is certainly the place to put configuration information.

This is just pure ruby so you might put som constants or even methods
here, thjs is then available everywhere in your app. (I think)

Hope that helps.

Hello Andrew,

   # Include your application configuration below

Any help would be much appreciated.

You have a few options. If you want static configuration, then yes,
Ruby code in environment.rb is fine.

If you want the users to be able to change some or all of the
configuration, you'll need to either develope your own Configuration
model and store that in the database (or a YAML file, or any other
way), or use one of the available plugins.

I haven't tried any of the plugins, because I developed my own version
of Configuration before they were available. Can't help you there.

Hope that helps !

I'd like to emphasize Francois' point about environment.rb being for static
configuration. Environment.rb is loaded once at application start and never
re-examined. Changes to any paramenter require a server restart to take
effect. I use the YAML approach for a menuing system I wrote, and
occasionally I'll use a database. Someone was talking about an acts_as_hash
plugin, which would be ideal for settings where you'd like to make a change
but not restart the server.

Hope this helps.

Andrew Stewart-6 wrote:

I'd like to emphasize Francois' point about environment.rb being for static
configuration. Environment.rb is loaded once at application start and never
re-examined. Changes to any paramenter require a server restart to take
effect. I use the YAML approach for a menuing system I wrote, and
occasionally I'll use a database. Someone was talking about an acts_as_hash
plugin, which would be ideal for settings where you'd like to make a change
but not restart the server.

Thank you everyone for your replies. It's been useful to hear your views.

I'm just after static configuration on a per-environment basis, so for now I'm simply going to put constants in config/environments/*.rb and access those directly from my application code.

Thanks again for your advice and suggestions,
Andy Stewart

This is how I implemented it. I got the idea from this mailing list.

In environment.rb

Site wide variables