When using Devise to create custom model User
. The views are created via $ rails g devise:views users
How to tell Devise to use templates in views/users/mailer
when sending confirmation emails to user??
Asked
Active
Viewed 620 times
1

MorboRe'
- 151
- 10
1 Answers
2
step 1, uncomment the "config.mailer" line and rename Devise::Mailer
to your own Mailer Class
# config/initializers/devise.rb
# Configure the class responsible to send e-mails.
# config.mailer = 'Devise::Mailer'
config.mailer = 'CustomMailer'
step 2, create a new file with CustomMailer
class which inherits from Devise::Mailer
. Then override method headers_for
to set template_path
to the folder with customized Devise
views
# app/mailers/my_mailer.rb
class CustomMailer < Devise::Mailer
def headers_for(action, opts)
super.merge!({template_path: 'users/mailer'}) # app/views/users/mailer
end
end
-
Starting from Rails 7 you need to be aware that including `config.mailer = 'CustomMailer' needs this custom-mailer (and also Devise mailer) to be required in Devise initializer first as well. Related Q&A here: https://stackoverflow.com/a/72308475/1677069 – Andres May 20 '22 at 10:28