# Initializers and automatically running code

**URL:** <https://www.ruby-forum.com/t/initializers-and-automatically-running-code/170772>\
**Category:** Rails\
**Created:** [June 22, 2009, 6:18pm UTC](https://www.ruby-forum.com/t/initializers-and-automatically-running-code/170772 "2009-06-22T18:18:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![talex83](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/54ee81/32.png) [@talex83](https://www.ruby-forum.com/u/talex83)\
**Post date:** [June 22, 2009, 6:18pm UTC](https://www.ruby-forum.com/t/initializers-and-automatically-running-code/170772/1 "2009-06-22T18:18:13Z")

</div>

I want to decorate ActiveRecord with a new method so that any classes  
that inherit from it also have the method.

I’ve been told that initializers are the way to go, yet when I put a  
file in initializers containing:

class \<\< ActiveRecord::Base

def methodName(params)  
end

end

The method doesn’t exist. While I realize this may be the simplest of  
errors, I was going on some advice and I more or less would likely  
benefit of having a full explanation of what’s going on with  
initializers, “class \<\<” and how the best way to add methods to  
ActiveRecord without actually modifying the ActiveRecord class itself…

---

<div class="post-metadata">

**Author:** ![talex83](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/54ee81/32.png) [@talex83](https://www.ruby-forum.com/u/talex83)\
**Post date:** [June 22, 2009, 6:26pm UTC](https://www.ruby-forum.com/t/initializers-and-automatically-running-code/170772/2 "2009-06-22T18:26:30Z")

</div>

On Jun 22, 5:18 pm, Alexander T. \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> end

Did you want to add a class method or were you intending to add an  
instance method ?

Fred

---

<div class="post-metadata">

**Author:** ![talex83](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/54ee81/32.png) [@talex83](https://www.ruby-forum.com/u/talex83)\
**Post date:** [June 22, 2009, 6:28pm UTC](https://www.ruby-forum.com/t/initializers-and-automatically-running-code/170772/3 "2009-06-22T18:28:45Z")

</div>

Frederick C. wrote:

> On Jun 22, 5:18ï¿½pm, Alexander T. \<rails-mailing-l…@andreas-  
> [s.net](http://s.net)\> wrote:
> 
> > end
> 
> Did you want to add a class method or were you intending to add an  
> instance method ?
> 
> Fred

Instance. So any instances of ActiveRecord (my models) would have the  
method.
