# How to substitute my class method for rails' version

**URL:** <https://www.ruby-forum.com/t/how-to-substitute-my-class-method-for-rails-version/90591>\
**Category:** Rails\
**Created:** [March 30, 2007, 4:40am UTC](https://www.ruby-forum.com/t/how-to-substitute-my-class-method-for-rails-version/90591 "2007-03-30T04:40:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [March 30, 2007, 4:40am UTC](https://www.ruby-forum.com/t/how-to-substitute-my-class-method-for-rails-version/90591/1 "2007-03-30T04:40:41Z")

</div>

I’m putting together a plugin and it has to monkey-patch some of  
ActionMailer. A good deal of AM’s magic is class methods, and I’m  
wanting to  
do something like:

module ActionMailer  
class Base  
class \<\< self  
def create!(method\_name, \*parameters)  
puts “yippee, skippee, I got here!”  
# do something useful  
end  
end  
end  
end

So, I go ahead and do this, hoping to simply drop my create! in over  
ActionMailer’s, but in my tests, the ActionMailer code is called and not  
mine.

## Can anyone tell me what I’m missing here?

View this message in context:  
[http://www.nabble.com/how-to-substitute-my-class-method-for-rails'-version-tf3489926.html#a9746360](http://www.nabble.com/how-to-substitute-my-class-method-for-rails%27-version-tf3489926.html#a9746360)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [March 30, 2007, 10:15am UTC](https://www.ruby-forum.com/t/how-to-substitute-my-class-method-for-rails-version/90591/2 "2007-03-30T10:15:36Z")

</div>

On Mar 30, 2007, at 4:39 AM, s.ross wrote:

> ```
> # do something useful
> 
> ```
> 
> Can anyone tell me what I’m missing here?  
> The technique is OK, you probably knew this, so next thing to look at  
> is which class is being loaded later, that one is the winner.

– fxn

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [March 30, 2007, 7:09pm UTC](https://www.ruby-forum.com/t/how-to-substitute-my-class-method-for-rails-version/90591/3 "2007-03-30T19:09:27Z")

</div>

Yeah, I finally got it… The way AM is constructed is somewhat  
complicated so I had one detail wrong and it led me to the wrong  
conclusion: that I had syntactically screwed up.

Thx,

–sr

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [March 30, 2007, 9:23pm UTC](https://www.ruby-forum.com/t/how-to-substitute-my-class-method-for-rails-version/90591/4 "2007-03-30T21:23:45Z")

</div>

Absolutely. The real code is released in a plugin and you can browse the  
repo. The code you want to see is at:

[http://svn.calicowebdev.com/plugins/templated\_mailer/lib/templated\_mailer.rb](http://svn.calicowebdev.com/plugins/templated_mailer/lib/templated_mailer.rb)

I announced the plugin on the Haml list because it applies to templating  
languages other than rhtml, but here’s a redux of the announcement:

I just put a plugin together specifically to make ActionMailer play nice  
with Haml. It also will work with Markaby or any other “unsupported”  
markup  
language.  
Initially, this code was s’posed to be a Rails patch, but it keeps not  
showing up in trunk, so here it is as a plugin. You can read about it  
here:

[http://calicowebdev.com/blog/show/10](http://calicowebdev.com/blog/show/10)

You can get it here:

[http://svn.calicowebdev.com/plugins/templated\_mailer](http://svn.calicowebdev.com/plugins/templated_mailer)

Reader’s Digest version of instructions:

Step 1: Get it using svn or ‘ruby script/plugin install  
[http://svn.calicowebdev.com/plugins/templated\_mailer](http://svn.calicowebdev.com/plugins/templated_mailer)’  
Step 2: Add the following line to your environment.rb

ActionMailer::Base.register\_template\_extension(‘haml’)

Step 3: Just stop typing “rhtml”.

There is no Trac or anything, but your can email me with bugs or  
comments  
(and be gentle).

longinos wrote:

> > Yeah, I finally got it… The way AM is constructed is somewhat  
> > complicated so I had one detail wrong and it led me to the wrong  
> > conclusion: that I had syntactically screwed up.
> > 
> > Thx,
> > 
> > –sr

–  
View this message in context:  
[http://www.nabble.com/how-to-substitute-my-class-method-for-rails'-version-tf3489926.html#a9759336](http://www.nabble.com/how-to-substitute-my-class-method-for-rails%27-version-tf3489926.html#a9759336)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [March 30, 2007, 9:14pm UTC](https://www.ruby-forum.com/t/how-to-substitute-my-class-method-for-rails-version/90591/5 "2007-03-30T21:14:32Z")

</div>

For educational reasons 🙂 would you mind posting the “clean” code?

Thanks!

Shawn

Steve R. wrote:

> Yeah, I finally got it… The way AM is constructed is somewhat  
> complicated so I had one detail wrong and it led me to the wrong  
> conclusion: that I had syntactically screwed up.
> 
> Thx,
> 
> –sr
