# Constants not visible in controllers or models

**URL:** <https://www.ruby-forum.com/t/constants-not-visible-in-controllers-or-models/159961>\
**Category:** Rails\
**Created:** [February 10, 2009, 1:10pm UTC](https://www.ruby-forum.com/t/constants-not-visible-in-controllers-or-models/159961 "2009-02-10T13:10:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [February 10, 2009, 1:10pm UTC](https://www.ruby-forum.com/t/constants-not-visible-in-controllers-or-models/159961/1 "2009-02-10T13:10:23Z")

</div>

Hi,

I might be being a bit thick today but I have a problem that I can’t  
seem to shake.

I have some configuration data in a yaml file that I load with an  
initializer.

AVATARS\_CONFIG = YAML.load\_file("#{RAILS\_ROOT}/config/avatars.yml")

The information includes where to save upload files and other stuff so  
it is needed in several places. One of the controllers can reference  
AVATARS\_CONFIG, but the model, avatars.rb cannot. So I have to have  
the same line in any controller or model that needs it. Which looks to  
be very messy not to mention inconsistent - some places need it, other  
don’t.

I’ve tried to make them global, ie $AVATARS\_CONFIG, but it doesn’t  
seem to work.

Anyone have any idea how I might get this and other constants I  
require to be available globally?

Thanks

---

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [February 10, 2009, 1:16pm UTC](https://www.ruby-forum.com/t/constants-not-visible-in-controllers-or-models/159961/2 "2009-02-10T13:16:56Z")

</div>

Where have you defined those constants?

Constants should be accessed with NameOfTheClass::NAME\_OF\_THE\_CONSTANT

- 

Maurício Linhares  
[http://alinhavado.wordpress.com/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
(en)

---

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [February 10, 2009, 10:56pm UTC](https://www.ruby-forum.com/t/constants-not-visible-in-controllers-or-models/159961/3 "2009-02-10T22:56:08Z")

</div>

Sorry, disregard everything I said. I’m having a blond moment. My  
initialiser scripts were actually .yml files rather than .rb files. So  
the line

AVATARS\_CONFIG = YAML.load\_file("#{RAILS\_ROOT}/config/avatars.yml")

didn’t actually do anything. Didn’t error either but it’s all my fault.

Sorry to waste your time
