Both devise confirmable (email confirmation when user signs up) and reconfirmable (email confirmation when user changes email) modules send the same email template, "confirmation_instructions". How do I get it so that a different email template is used for confirmable?
You can override options[:template_name]
in the #confirmation_instructions
method of your mailer.
class AuthMailer < Devise::Mailer
helper :application
include Devise::Controllers::UrlHelpers
default template_path: 'devise/mailer'
def confirmation_instructions(record, token, options={})
# Use different e-mail templates for signup e-mail confirmation and for when a user changes e-mail address.
if record.pending_reconfirmation?
options[:template_name] = 'reconfirmation_instructions'
else
options[:template_name] = 'confirmation_instructions'
end
super
end
end
Also change this line from device.rb
# config.mailer = 'Devise::Mailer'
config.mailer = 'AuthMailer'
#Devise Mailer
def confirmation_instructions(record)
@resource = record
if @resource.pending_reconfirmation?
mail(to: @resource.unconfirmed_email, subject: "Confirm new email") do |format|
format.html { render ... }
end
else
mail(to: @resource.email, subject: "Confirm new account") do |format|
format.html { render .... }
end
end
end
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