I want to create a base class for a few of my models, as follows: class SingletonRecord < ActiveRecord::Base def self.get instance = self.find_all[0] instance ||= Current.new return instance end def save self.delete_all super end end Then I create a subclass model like so: require ''singletonrecord'' class Current < SingletonRecord end This works great in the console, i.e. Current.get does what I''d expect. But it doesn''t work through the web interface - it tells me "SingletonRecord uninitialized constant". Why? -- Posted via http://www.ruby-forum.com/.
Ryan Allen
2006-Jun-14 09:29 UTC
[Rails] Re: Base class model not found, even with require
Hi Adam, You shouldn''t have to put the ''require'' at the top of the file. Rails can find your models as long as they''re named correctly according to the convention. What is the filename you have SingletonRecord saved as? It should be singleton_record.rb. Ryan. -- Posted via http://www.ruby-forum.com/.
Ryan Allen
2006-Jun-14 09:33 UTC
[Rails] Re: Base class model not found, even with require
Adam, I didn''t notice you were including it as ''singletonrecord'', so I''m assuming you have your file named singletonrecord.rb. Rename it to singleton_record.rb and remove the require ''singletonrecord'' line. Rails will automagically find singleton_record.rb when you extend from SingletonRecord in your Current class. Ryan. -- Posted via http://www.ruby-forum.com/.