# How To Add Extra Application Configuration

**URL:** <https://www.ruby-forum.com/t/how-to-add-extra-application-configuration/71787>\
**Category:** Rails\
**Created:** [October 11, 2006, 2:01pm UTC](https://www.ruby-forum.com/t/how-to-add-extra-application-configuration/71787 "2006-10-11T14:01:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [October 11, 2006, 2:01pm UTC](https://www.ruby-forum.com/t/how-to-add-extra-application-configuration/71787/1 "2006-10-11T14:01:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [October 11, 2006, 2:15pm UTC](https://www.ruby-forum.com/t/how-to-add-extra-application-configuration/71787/2 "2006-10-11T14:15:43Z")

</div>

On 10/11/06, Andrew S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [October 11, 2006, 9:45pm UTC](https://www.ruby-forum.com/t/how-to-add-extra-application-configuration/71787/3 "2006-10-11T21:45:57Z")

</div>

Hello Andrew,

2006/10/11, Andrew S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> # 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://blog.teksol.info/)  
[http://piston.rubyforge.org/](http://piston.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [October 12, 2006, 12:29pm UTC](https://www.ruby-forum.com/t/how-to-add-extra-application-configuration/71787/4 "2006-10-12T12:29:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [October 11, 2006, 10:33pm UTC](https://www.ruby-forum.com/t/how-to-add-extra-application-configuration/71787/5 "2006-10-11T22:33:10Z")

</div>

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](http://www.nabble.com/How-To-Add-Extra-Application-Configuration-tf2422957.html#a6764032)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [October 18, 2006, 10:38am UTC](https://www.ruby-forum.com/t/how-to-add-extra-application-configuration/71787/6 "2006-10-18T10:38:49Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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!
