I'm following michael harlt rails tutorial but i get this error
Missing template layouts/mailer with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :jbuilder]}. Searched in: * "/home/ubuntu/workspace/app/views"
when previewing account activation
This is my user_mailer.rb
class UserMailer < ApplicationMailer
def account_activation(user)
@user = user
mail to: user.email, subject: "Account activation"
end
def password_reset
@greeting = "Hi"
mail to: "[email protected]"
end
end
and the error highlights the line that says
mail to: user.email, subject: "Account activation"
I tried adding layout 'mailer' in user_mailer.rb but it doesn't work.
EDIT: Here is the screenshot of the error
The screenshot of my folders
I had the same problem, and it seemed to work for me if I commented out the layout 'mailer' line in application_mailer
eg
class ApplicationMailer < ActionMailer::Base
default from: '[email protected]'
# layout 'mailer'
end
The issue is the next:
to generate this mailer you use this command
$rails generate mailer UserMailer account_activation password_reset
sending back
create app/mailers/user_mailer.rb
create app/mailers/application_mailer.rb
invoke erb
create app/views/user_mailer
create app/views/layouts/mailer.text.erb
create app/views/layouts/mailer.html.erb
invoke test_unit
create test/mailers/user_mailer_test.rb
create test/mailers/previews/user_mailer_preview.rb
by a strange way app/views/layouts/mailer.html.erb
file is not generated so when you call
layout 'mailer'
the rails core send you this error
"Missing template layouts/mailer"
you can resolve this by 2 ways.
First: comment out or delete layout 'mailer'.
Second: Creating the file.
Another ways like 'layout mailer' are bad practices cause this syntax have no sense for Rails.
If you create the file, use this code to fill it
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>
<body>
<%= yield %>
</body>
</html>
I had this same issue and what resolved it is ensuring I had two files in .../app/views/layouts/
: mailer.html.erb
and mailer.text.erb
.
mailer.html.erb
:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>
<body>
<%= yield %>
</body>
</html>
mailer.text.erb
:
<%= yield %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With