Render Partial for Email Template

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.

Posted November 30th, 2006 at 9:12 pm in Ruby on Rails | Permalink

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Leave a response: