Forum: Ruby on Rails Base class model not found, even with require

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.
0339cd0817ab238f955da3460a22d77c?d=identicon&s=25 Adam W. (hirodusk)
on 2006-06-14 11:20
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?
Ryan Allen (Guest)
on 2006-06-14 11:29
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.
Ryan Allen (Guest)
on 2006-06-14 11:33
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.
This topic is locked and can not be replied to.