# Extending the ActiveRecord:Base class

**URL:** <https://www.ruby-forum.com/t/extending-the-activerecord-base-class/122086>\
**Category:** Rails\
**Created:** [December 4, 2007, 2:40pm UTC](https://www.ruby-forum.com/t/extending-the-activerecord-base-class/122086 "2007-12-04T14:40:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![harm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b4bc9f/32.png) [@harm](https://www.ruby-forum.com/u/harm)\
**Post date:** [December 4, 2007, 2:40pm UTC](https://www.ruby-forum.com/t/extending-the-activerecord-base-class/122086/1 "2007-12-04T14:40:54Z")

</div>

Dear list,

I’d like to make an ‘after\_find’ call for each and every AR model I  
defined. In AWDWR page 376 they do so by opening up the AR class like  
this:  
class ActiveRecord::Base  
def self.some\_method  
return ‘foo’  
end  
end

All nice and well but where should I store this class?? According to  
the chapter it should go in app/models. So I placed a file called  
base.rb in app/models/active\_record. To no avail. Placing it in app/  
models did no good either.

I know I can do this by defining a module in lib/ and include that in  
all my models but that is just not as pretty.

With kind regards,  
Harm

---

<div class="post-metadata">

**Author:** ![harm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b4bc9f/32.png) [@harm](https://www.ruby-forum.com/u/harm)\
**Post date:** [December 4, 2007, 3:03pm UTC](https://www.ruby-forum.com/t/extending-the-activerecord-base-class/122086/2 "2007-12-04T15:03:46Z")

</div>

On 4 Dec 2007, at 13:40, harm wrote:

> end
> 
> All nice and well but where should I store this class?? According to  
> the chapter it should go in app/models. So I placed a file called  
> base.rb in app/models/active\_record. To no avail. Placing it in app/  
> models did no good either.
> 
> I know I can do this by defining a module in lib/ and include that in  
> all my models but that is just not as pretty.

Put it wherever you want. In environment.rb require that file.  
An alternative would be

class MyBaseClass \< ActiveRecord::Base  
self.abstract\_class = true  
[your funkiness here]  
end

and then have all your classes inherit from MyBaseClass

Fred

---

<div class="post-metadata">

**Author:** ![harm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b4bc9f/32.png) [@harm](https://www.ruby-forum.com/u/harm)\
**Post date:** [December 4, 2007, 3:44pm UTC](https://www.ruby-forum.com/t/extending-the-activerecord-base-class/122086/3 "2007-12-04T15:44:16Z")

</div>

Aha! So I should just require it. I was hoping that would go  
‘automagically’. Thanks for the reply.

On Dec 4, 3:02 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
