# Base class model not found, even with require

**URL:** <https://www.ruby-forum.com/t/base-class-model-not-found-even-with-require/63338>\
**Category:** Rails\
**Created:** [June 14, 2006, 11:20am UTC](https://www.ruby-forum.com/t/base-class-model-not-found-even-with-require/63338 "2006-06-14T11:20:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hirodusk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6f9a4e/32.png) [@hirodusk](https://www.ruby-forum.com/u/hirodusk)\
**Post date:** [June 14, 2006, 11:20am UTC](https://www.ruby-forum.com/t/base-class-model-not-found-even-with-require/63338/1 "2006-06-14T11:20:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hirodusk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6f9a4e/32.png) [@hirodusk](https://www.ruby-forum.com/u/hirodusk)\
**Post date:** [June 14, 2006, 11:29am UTC](https://www.ruby-forum.com/t/base-class-model-not-found-even-with-require/63338/2 "2006-06-14T11:29:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hirodusk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6f9a4e/32.png) [@hirodusk](https://www.ruby-forum.com/u/hirodusk)\
**Post date:** [June 14, 2006, 11:33am UTC](https://www.ruby-forum.com/t/base-class-model-not-found-even-with-require/63338/3 "2006-06-14T11:33:02Z")

</div>

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.
