5

两者都设计可确认(用户注册时的电子邮件确认)和可重新确认(用户更改电子邮件时的电子邮件确认)模块发送相同的电子邮件模板“confirmation_instructions”。如何获取它以便使用不同的电子邮件模板进行确认?

4

3 回答 3

9

您可以在邮件程序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'
于 2015-02-08T14:38:18.967 回答
7
#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
于 2013-05-02T16:03:53.197 回答
0

刚刚查看了文档,您可以在模型中覆盖一个 send_on_create_notification 方法。所以只需要重写这个方法,这样就不会发送确认电子邮件,而是发送另一封电子邮件。在那封电子邮件中,我只有确认链接。

于 2013-04-03T02:19:03.057 回答