# Rendering partials in ActionMailer?

**URL:** <https://www.ruby-forum.com/t/rendering-partials-in-actionmailer/55649>\
**Category:** Rails\
**Created:** [March 22, 2006, 6:33pm UTC](https://www.ruby-forum.com/t/rendering-partials-in-actionmailer/55649 "2006-03-22T18:33:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbraford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@sbraford](https://www.ruby-forum.com/u/sbraford)\
**Post date:** [March 22, 2006, 6:33pm UTC](https://www.ruby-forum.com/t/rendering-partials-in-actionmailer/55649/1 "2006-03-22T18:33:53Z")

</div>

Hello,

Is anyone out there rendering partials successfully in ActionMailer  
templates?

I am having trouble with this, and wasn’t sure if it was my  
configuration or something with a version of Rails I’m running.

We’ve got over 15 mailer templates, all working like a charm.

But we have a piece of shared code, that we’d really like to not have to  
copy & paste into 5 other different templates.

In case it has to do with my setup, here’s a bit about it:

In models/

class Mailer \< ActionMailer::Base  
…  
end

In views/mailer/ - I have:  
\_test.rhtml - the partial I’m trying to render  
send.rhtml - the template calling the partial

In send.rhtml, I’ve tried various incarnations of:

\<%= render :partial =\> “test” %\>

\<%= render\_partial(“mailer/test”) %\>

\<%= render\_partial(“test”) %\>

\<%= render\_file(“mailer/\_test.rhtml”, false) %\>

(one at a time, of course) … all to no avail.

The Error:

undefined method `controller\_path’ for Mailer:Class

My Config:

Ruby 1.8.4  
Edge Rails: Rev 3476  
OS X Tiger latest / all updates applied.

Any insight would be mucho appreciated!!

- Shanti

[http://sablog.com/](http://sablog.com/) - dispatches from the garage  
[http://sproutit.com/](http://sproutit.com/) - webapps for small businesses

ps. I have a ticket opened here, but I hope I can close it soon (due to  
_user_ error not a limit in Rails!):  
[http://dev.rubyonrails.org/ticket/4326](http://dev.rubyonrails.org/ticket/4326)

---

<div class="post-metadata">

**Author:** ![sbraford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@sbraford](https://www.ruby-forum.com/u/sbraford)\
**Post date:** [March 23, 2006, 6:46pm UTC](https://www.ruby-forum.com/t/rendering-partials-in-actionmailer/55649/2 "2006-03-23T18:46:12Z")

</div>

Shanti B. wrote:

> Hello,
> 
> Is anyone out there rendering partials successfully in ActionMailer  
> templates?

Hi,

I haven’t tried with partials since helpers worked fine for me, maybe  
you could take this route as well.

–  
Agnieszka

---

<div class="post-metadata">

**Author:** ![sbraford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@sbraford](https://www.ruby-forum.com/u/sbraford)\
**Post date:** [March 24, 2006, 1:30pm UTC](https://www.ruby-forum.com/t/rendering-partials-in-actionmailer/55649/3 "2006-03-24T13:30:59Z")

</div>

I’ve got this piece of code in an AM template:

\<%= render :partial =\> ‘…/shared/listing’ %\>

I think the default path is the current path of the AM template, so  
…/ puts it down into app/views/. That line will render  
app/views/shared/\_listing.rhtml.

-Jonathan

---

<div class="post-metadata">

**Author:** ![sbraford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@sbraford](https://www.ruby-forum.com/u/sbraford)\
**Post date:** [March 24, 2006, 4:26pm UTC](https://www.ruby-forum.com/t/rendering-partials-in-actionmailer/55649/4 "2006-03-24T16:26:31Z")

</div>

Jonathan V. wrote:

> I’ve got this piece of code in an AM template:
> 
> \<%= render :partial =\> ‘…/shared/listing’ %\>
> 
> I think the default path is the current path of the AM template, so  
> …/ puts it down into app/views/. That line will render  
> app/views/shared/\_listing.rhtml.

Jonathan - you’re a lifesaver. You just saved me from 6 copy&paste jobs  
anytime the template changed =)

Posted the workaround to this ticket for future googlers:  
[http://dev.rubyonrails.org/ticket/2926](http://dev.rubyonrails.org/ticket/2926)

- Shanti
