Missing template layout / mailer using {: locale => [: en] ,: formats => [: html],

I follow the instructions of michael harlt rails, but I get this error

There is no template layout / mailer with {: locale => [: en] ,: formats => [: html] ,: variantants => [] ,: handlers => [: raw ,: erb ,: html ,: builder, : ruby โ€‹โ€‹,: coffee ,: jbuilder]}. Search: * "/ 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: " to@example.org " end end 

and the error highlights the line that says

 mail to: user.email, subject: "Account activation" 

I tried adding the 'mailer' layout to user_mailer.rb, but it does not work.

EDIT: Here is a screenshot of the error

Screenshot of my folders

+7
ruby ruby-on-rails ruby-on-rails-3 web ruby-on-rails-5
source share
5 answers

If you have not already done so, you will need a folder inside the views called user_mailer, and inside it you will need a file for each of these methods (account_activation.html.erb and password_reset.html.erb). Your email template will be here.

+2
source share

The problem is as follows:

to create 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 

in a weird way app/views/layouts/mailer.html.erb file is not generated, so when you call

layout 'mailer'

the core of the rails will send you this error

"Missing layout template / mailer"

You can solve this in two ways.

First: comment or delete the 'mailer' layout.
Second: Create a file.

Other methods, such as mock mail, are incorrect methods because this syntax makes no sense to Rails.

If you are creating a file, use this code to populate 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> 
+5
source share

I had the same problem and decided that I have 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 %> 
+5
source share

I had the same problem and it seemed to work for me if I commented out the "mailer" layout line in application_mailer

eg,

 class ApplicationMailer < ActionMailer::Base default from: ' noreply@taskflow.herokuapp.com ' # layout 'mailer' end 
+4
source share

Make sure you have the app/mailers/application_mailer.rb file From the Hartl tutorial:

 class ApplicationMailer < ActionMailer::Base default from: " noreply@example.com " layout 'mailer' end 
0
source share

All Articles