Forum: Ruby on Rails error: uninitialized constant

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.
Sebastian F. (Guest)
on 2006-03-01 09:18
(Received via mailing list)
total rails nuby here. I have a table "thumbnails", hence the model
Thumbnail. I'm extending the Thumbnail class with a few constants
needed for thumbnail cropping:

class Thumbnail < ActiveRecord::Base

SOURCE_FILE_PATH = "path/to/source"
TARGET_FILE_PATH = "path/to/target"


Now, in my controller i'm trying to access these:

source_path = Thumbnail::SOURCE_FILE_PATH

however, i get an error:

uninitialized constant SOURCE_FILE_PATH
active_support/dependencies.rb:200:in `const_missing'
This error occured while loading the following files:

so, it seems it interprets the scope operator as a request for class
SOURCE_FILE_PATH in module Thumbnail. Doing this straight in Ruby
works fine, however. I've also seen a constant being called that way
from the View in the Agile book. anybody could enlighten me on what
is different here?

is this a bad way of dealing with "hardwired" data in general? should
this be in its own model even though its very much related to the
"thumbnail" logic? I'm still having a somewhat hard time to wrap by
head around the various concepts of separation, so please forgive me
for sounding stupid. any good suggestions on how to incorporate that
the Rails-way.

Nicholas H. (Guest)
on 2006-04-07 17:25
(Received via mailing list)
Does any one have an answer to this, I would love to know!

MyModel::MyConstant give an initialization error. Why?

Nicholas H. (Guest)
on 2006-04-07 17:25
(Received via mailing list)
Sorry, MyModel::MYCONSTANT give an initialization error.
This topic is locked and can not be replied to.