Forum: Ruby on Rails Need help making a "system wide" config object available

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
84ff5f3d1f5b912a04d2acf63901501b?d=identicon&s=25 Chad Thatcher (builderchad)
on 2007-02-02 22:53
I need to make a config object (a static, unchanging object created
preferably at the application level) available to not only certain
models but other housekeeping objects as well.

I have a config object that is created once and remains in that state
for its entire life so I want to be able to access this object
everywhere where I need it as it is quite large and recreating it more
than once in the same process would be wasteful.

So far I am instantiating it in application.rb but is this the right

How can I refer to the main application object from within a model?
What is the best way of getting at this object?

Ae97ad0da5c7887be291561eb1720093?d=identicon&s=25 Alex Soto (asoto)
on 2007-02-03 18:27
(Received via mailing list)
I do something similar to the following:

module Config
  CONFIG = {
    :config_value_1 => "some string",
    :config_object_1 =>

then in your environment.rb just:
require 'config'

Then in your code you could:
include Config

then CONFIG[:config_value_1] where you need the config values in your

However, there is no concept of a 'shared' config across all your
mongrel processes for example, each process would have it's own copy
of the config.  I suppose you could try something using memcached or
similar to share things across procs.

On Feb 2, 1:53 pm, Chad Thatcher <>
84ff5f3d1f5b912a04d2acf63901501b?d=identicon&s=25 Chad Thatcher (builderchad)
on 2007-02-03 19:25
Thanks Alex, I only need for a single process where the config is reused
in many places - I wanted to avoid loading it over and over in the same
page hit.  So what  you have suggested looks good and I'll have a go.
This topic is locked and can not be replied to.