Error: uninitialized constant

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.


Does any one have an answer to this, I would love to know!

MyModel::MyConstant give an initialization error. Why?


Sorry, MyModel::MYCONSTANT give an initialization error.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs