设计确认(用户注册时的电子邮件确认)和可重新配置(用户更改电子邮件时的电子邮件确认)模块发送相同的电子邮件模板“confirmation_instructions”。如何获取它以便使用不同的电子邮件模板进行确认?
答案 0 :(得分:7)
您可以在邮件程序的options[:template_name]
方法中覆盖#confirmation_instructions
。
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
还要从device.rb更改此行
# config.mailer = 'Devise::Mailer'
config.mailer = 'AuthMailer'
答案 1 :(得分:6)
#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
答案 2 :(得分:0)
只需查看文档,就可以在模型中覆盖send_on_create_notification方法。因此,只需要覆盖此方法,以便不发送确认电子邮件,而是发送另一个确认电子邮件。在那封电子邮件中,我将只有确认链接。