Ian Fleeton
Ian Fleeton

Reputation: 1157

Why do I have to specify text format to render template with ActionMailer?

I'm using ActionMailer 3.0.7

According to the docs plain text emails are the default. So if I have an EnquiryNotifier mailer with a notify method then I expect that app/views/enquiry_notifier/notify.text.plain.erb will be rendered.

If I simply use mail(someparams) within the notify method then the body of the email is empty.

I read that ActionMailer is meant to scan the view directory to look for all types of templates.

However, if I specify the format within a block and do

mail(:to => 'somebody', :subject => 'something') do |format|
    format.text
end

then my template notify.text.plain.erb does get rendered.

Maybe unrelated: If I don't specify the format but rename the template to notify.erb then it works but the email is sent as text/html.

Upvotes: 3

Views: 1438

Answers (1)

twmills
twmills

Reputation: 3015

Here's what seems to work for me in rails 3.0.6:

  1. I don't specify a format at all in my mailer class, I just let it find the view automatically.
  2. I name my view "notify.text.erb"

Upvotes: 5

Related Questions