Forum: Ruby on Rails Constants not visible in controllers or models

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0bfcd61fc289de2e441929ecfd00b0ed?d=identicon&s=25 Peter Hickman (Guest)
on 2009-02-10 13:10
(Received via mailing list)
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
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-02-10 13:16
(Received via mailing list)
Where have you defined those constants?

Constants should be accessed with NameOfTheClass::NAME_OF_THE_CONSTANT

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)
0bfcd61fc289de2e441929ecfd00b0ed?d=identicon&s=25 Peter Hickman (Guest)
on 2009-02-10 22:56
(Received via mailing list)
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
This topic is locked and can not be replied to.