Devise不会覆盖电子邮件视图

时间:2017-02-03 18:17:52

标签: ruby-on-rails devise

我有我的范围视图reset_password_instructions.html

和我的devise.rb

  config.scoped_views = true

它在开发中运行良好并发送自定义电子邮件。但是,在生产中,当用户收到电子邮件时,设备会发送默认模板。

如何在生产中解决此问题?

1 个答案:

答案 0 :(得分:0)

当我使用设计时,这就是我发送自己的电子邮件

class MyMailer < Devise::Mailer   
  helper :application # gives access to all helpers defined within `application_helper`.
  include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
  default template_path: 'devise/mailer' # to make sure that your mailer uses the devise views
end

现在,在您的config/initializers/devise.rb中,您可以将config.mailer设置为"MyMailer"

您现在可以像使用任何其他邮件一样使用MyMailer。如果您想覆盖特定邮件以添加额外标题,您可以通过简单地覆盖方法并在自定义方法结束时调用super来触发Devise的默认行为。

您还可以通过手动设置选项哈希来覆盖任何基本标头(来自,reply_to等):

def confirmation_instructions(record, token, opts={})
  headers["Custom-header"] = "Bar"
  opts[:from] = 'my_custom_from@example.com'
  opts[:reply_to] = 'my_custom_from@example.com'
  super
end

为了获得预览(如果用户是您的设计型号名称):

# test/mailers/previews/my_mailer_preview.rb
# Preview all emails at http://localhost:3000/rails/mailers/my_mailer

class MyMailerPreview < ActionMailer::Preview

  def confirmation_instructions
    MyMailer.confirmation_instructions(User.first, "faketoken", {})
  end

  def reset_password_instructions
    MyMailer.reset_password_instructions(User.first, "faketoken", {})
  end

  def unlock_instructions
    MyMailer.unlock_instructions(User.first, "faketoken", {})
  end
end

我希望这很有用:)

相关问题