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" TARGET_WIDTH = 100 TARGET_HEIGHT = 100 end 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 /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/ active_support/dependencies.rb:200:in `const_missing'' This error occured while loading the following files: source_file_path.rb 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. thanks. sebastian
Does any one have an answer to this, I would love to know! MyModel::MyConstant give an initialization error. Why? Cheers, Nicholas On 3/1/06, Sebastian Friedrich <sebastian@feldpost.com> wrote:> 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" > TARGET_WIDTH = 100 > TARGET_HEIGHT = 100 > > end > > 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 > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/ > active_support/dependencies.rb:200:in `const_missing'' > This error occured while loading the following files: > source_file_path.rb > > 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. > > thanks. > sebastian > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Sorry, MyModel::MYCONSTANT give an initialization error. On 4/7/06, Nicholas Henry <nicholas.henry@gmail.com> wrote:> Does any one have an answer to this, I would love to know! > > MyModel::MyConstant give an initialization error. Why? > > Cheers, > Nicholas > > On 3/1/06, Sebastian Friedrich <sebastian@feldpost.com> wrote: > > 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" > > TARGET_WIDTH = 100 > > TARGET_HEIGHT = 100 > > > > end > > > > 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 > > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/ > > active_support/dependencies.rb:200:in `const_missing'' > > This error occured while loading the following files: > > source_file_path.rb > > > > 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. > > > > thanks. > > sebastian > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > >