Reputation: 731
I have stuck with such problem: I create MessageMailer < ActionMailer, and it works correct except that it does not take email layouts which I put in the folder view/message_mailer. What is missing for these layout would work?
My files:
mailers/message_mailer.rb
class MessageMailer < ApplicationMailer
default :to => "[email protected]"
def message_me(msg)
@msg = msg
mail from: @msg.email, subject: @msg.subject, body: @msg.content
end
end
views/message_mailer/message_me.text.erb
A question form contact form:
Name: <%= @msg.name %>
Email: <%= @msg.email %>
Contact: <%= @msg.content %>
The ActionMailer does not use this template, it just renders a simple email like this:
Sent mail to [email protected] (8.2ms)
Date: Sun, 07 Feb 2016 17:19:19 +0300
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: message subject
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
There is message content
Upvotes: 1
Views: 932
Reputation: 2113
Template not used in your mail because you are using mail
method with body:
argument which forces mailer to build email without template.
Find more useful info about rails mailer in Ruby on Rails guide
Upvotes: 4