Usage:
class ApplicationMailer < ActionMailer::Base
def post_notification(recipients, post)
@recipients = recipients
@subject = "[#{post.account.name} #{post.title}]"
@body["post"] = post
@from = post.author.email_address_with_name
end
def comment_notification(recipient, comment)
@recipients = recipient.email_address_with_name
@subject = "[#{comment.post.project.client.firm.account.name}]" +
" Re: #{comment.post.title}"
@body["comment"] = comment
@from = comment.author.email_address_with_name
@sent_on = comment.posted_on
end
end
# After this post_notification will look for "templates/application_mailer/post_notification.rhtml"
ApplicationMailer.template_root = "templates"
ApplicationMailer.create_comment_notification(david, hello_world) # => a tmail object
ApplicationMailer.deliver_comment_notification(david, hello_world) # sends the email
Methods
Attributes
| [RW] | bcc | |
| [RW] | body | |
| [RW] | cc | |
| [RW] | from | |
| [RW] | recipients | |
| [RW] | sent_on | |
| [RW] | subject |
Private Class methods
[ show source ]
# File lib/action_mailer/base.rb, line 85
85: def create_from_action(method_name, *parameters)
86: mailer = new
87: mailer.body = {}
88: mailer.send(method_name, *parameters)
89:
90: if String === mailer.body
91: mail = create(mailer.recipients, mailer.subject, mailer.body, mailer.from, mailer.sent_on)
92: else
93: mail = create(mailer.recipients, mailer.subject, render_body(mailer, method_name), mailer.from, mailer.sent_on)
94: end
95:
96: mail.bcc = @bcc if @bcc
97: mail.cc = @cc if @cc
98:
99: return mail
100: end
[ show source ]
# File lib/action_mailer/base.rb, line 102
102: def render_body(mailer, method_name)
103: ActionView::Base.new(template_path, mailer.body).render_file(method_name)
104: end
[ show source ]
# File lib/action_mailer/base.rb, line 106
106: def template_path
107: template_root + "/" + Inflector.underscore(self.to_s)
108: end