Well I’m writing quite a mail-intensive small application right now, and wanted to use the same template for 2 mail actions at some point. Searching for how to use template different from mailer action name didn’t give results, but looking into the ActionMailer code did (hail the open source!), so I’m placing it here to be a bit more visible )
Well the solution is quite laconic: just set self.template to what you need, just like you would render :action => :smth_different in ActionView. In example below enabled_notification action does it:
class GroupsMailer < ActionMailer::Base
#...
def disabled_notification(group, actor, disabled = true)
verb = disabled ? 'disabled' : 'enabled'
subject 'Usergroup \'%s\' was %s' % [group.name, verb]
body :group => group, :actor => actor,
:group_url => group_url(group.dn), :verb => verb
common_headers(actor)
end
def enabled_notification(group, actor)
disabled_notification(group, actor, false)
self.template = :disabled_notification
end
end
This was with actionmailer-2.0.1.
Filed under: ActionMailer, rails, tips | 3 Comments
Search
-
You are currently browsing the Artem Vasiliev's Weblog weblog archives.
Thank you for this,
I’ve been searching for a way to alter the ActionMailer template path but it is not documented well anywhere.
This is the only post that actually worked.
Welcome! ) Glad it helped.
Submit a documentation patch :)