# Accessing controller specific variables application-wide

**URL:** <https://www.ruby-forum.com/t/accessing-controller-specific-variables-application-wide/143085>\
**Category:** Rails\
**Created:** [July 15, 2008, 3:09am UTC](https://www.ruby-forum.com/t/accessing-controller-specific-variables-application-wide/143085 "2008-07-15T03:09:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamdorsey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed8c4c/32.png) [@adamdorsey](https://www.ruby-forum.com/u/adamdorsey)\
**Post date:** [July 15, 2008, 3:09am UTC](https://www.ruby-forum.com/t/accessing-controller-specific-variables-application-wide/143085/1 "2008-07-15T03:09:28Z")

</div>

Not sure if I described this the best in the subject, but here is my  
problem…

I have a ‘settings’ table, that I am storing application configuration  
data. On my settings “edit” page, I am just grabbing the first entry  
(you can’t add more entries, again, just a config table)

```auto

@setting = Setting.find(1)

```

I need to access some of that data in the main layout. For instance, the  
color (hex) of the template. The “name” of the application, etc.

How would I go about doing that?

---

<div class="post-metadata">

**Author:** ![adamdorsey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed8c4c/32.png) [@adamdorsey](https://www.ruby-forum.com/u/adamdorsey)\
**Post date:** [July 15, 2008, 11:33am UTC](https://www.ruby-forum.com/t/accessing-controller-specific-variables-application-wide/143085/2 "2008-07-15T11:33:36Z")

</div>

Many ways to do this.  
Either declare a before\_filter in application.rb and load  
the settings every time

before\_filter :load\_settings

def load\_settings  
@setting = Setting.find(1)  
end

Or, if you don’t need it that often, you can define a method

def get\_settings  
@setting ||= Setting.find(1)  
end

This will load the setting the first time it’s called. If it was  
called  
before, it just returns the @setting
