This was a particularly vexing problem that took me most of a night to resolve, so I’m sure this is going to come in handy.
So, you want to integrate ActionMailer into your Camping app. If you’ve tried already, I’m betting the part that’s got you stuck is how to set the template_root. Let’s walk through an example. The following is a snippet taken from a camping app:
module CampingMail::Models
ActionMailer::Base.template_root = "."
class Postcard < ActionMailer::Base
def pretty_card(contents)
...
end
end
end
So, with that set up, where is the template root? It’s here:
./camping_mail/models/
So the Postcard#pretty_card
template file would be found here:
./camping_mail/models/postcard/pretty_card.rhtml
When I was trying to guess at where the directory structure was, I kept trying variants of either ./camping_mail/postcard/pretty_card.rhtml
or ./postcard/pretty_card.rhtml
- the part I found unintuitive was the presence of the models directory. I’m reminded of Tim’s exploration of the http library source, because to get this info, I had to dive into the ActionMailer source to see what was being built. I sure wish I had thought to do that hours earlier than I did.
You may be wondering why I’m redefining ActionMailer::Base.template_root
in the Model – I tried putting it in the PostAmble, but the redefinition wouldn’t ‘stick’. This is the only place I could get the setting to take.
Copyright © 2009
Robert Hahn.
All Rights Reserved unless otherwise indicated.