Render Partial for Email Template

Posted by Curtis Miller Curtis Miller

As I create more automated email responses for my system, I realized I should follow the DRY (Don't Repeat Yourself) principle. So I started down a path to create a separate file containing a header and footer for my emails. At least that part I could rip out, right? Well…not exactly.

Turns out that rendering from within a mail template is not yet supported. In fact there is a Rails ticket open to address it, but it has not been corrected yet.

So, what to do? A suggestion from the Ruby Forums from the forums involves using a relative path when invoking render. For example:

<%= render :partial => '../foo' %>

Where ‘foo' refers to ‘_foo.rhtml' in the ‘app/views/' directory. This seems to work for me, but apparently this is only a workaround.

Hopefully this will be helpful to someone else who has the same problem.



Velocity Labs

Need web application development, maintenance for your existing app, or a third party code review?

Velocity Labs can help.

Hire us!