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

On 10/11/06, Andrew S. [email protected] wrote:

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

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,

2006/10/11, Andrew S. [email protected]:

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 !

François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/

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

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 S.-6 wrote:


View this message in context:
http://www.nabble.com/How-To-Add-Extra-Application-Configuration-tf2422957.html#a6764032
Sent from the RubyOnRails Users mailing list archive at Nabble.com.

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

In environment.rb

Site wide variables

SITE_YAML[RAILS_ENV][‘download_aviable_for’]

SITE_YAML = YAML::load_file(“#{RAILS_ROOT}/config/site.yml”)

Then in site.yml

development:
download_aviable_for : 24
test:
download_aviable_for : 24
production
download_aviable_for : 24

regards,
Leon L…

On 10/12/06, Andrew S. [email protected] wrote:

occasionally I’ll use a database. Someone was talking about an
and access those directly from my application code.

Thanks again for your advice and suggestions,
Andy S.


Never be afraid to try something new. Remember, amateurs built the ark;
professionals built the Titanic!