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