【问题标题】:Devise mail template for reset password设计用于重置密码的邮件模板
【发布时间】:2012-04-13 14:51:39
【问题描述】:

我想在通过设计(徽标图像)重置密码时发送的电子邮件中添加附件,并且我想使用用户的区域设置来本地化电子邮件文本。 谁能帮助并告诉我要覆盖什么来做到这一点?

【问题讨论】:

    标签: ruby-on-rails-3 devise


    【解决方案1】:

    您需要将徽标图像添加为附件。

    为此,请按照链接中的说明覆盖默认的 Devise::Mailer: https://github.com/plataformatec/devise/wiki/How-To:-Use-custom-mailer

    然后,使用attachments.inline['logo.png']=添加附件:

    def reset_password_instructions(record, opts={})
      attachments.inline['logo.png'] = File.read('app/assets/images/logo.png')
      super(record, opts)
    end
    

    并且在视图中你可以使用attachments['logo.png'].url:

    <%= image_tag(attachments['logo.png'].url, alt: 'Logo') %>
    

    【讨论】:

      【解决方案2】:

      只需运行rails generate devise:views 并在app/views/devise/mailer/reset_password_instructions.html.erb 中编辑模板

      【讨论】:

      • 但是我不能以这种方式添加图像。当我尝试这样做时,我只收到错误的链接。我必须在邮件中添加附件 - 我该怎么做?
      【解决方案3】:

      我正在为 rails 5 应用程序使用 devise 4.3。需要附加参数。

       def reset_password_instructions(record, token, opts={})
          attachments.inline['logo.png'] = File.read("#{Rails.root}/app/assets/images/logo.png")
          super(record, token, opts)
       end
      

      【讨论】:

        猜你喜欢
        • 2017-02-26
        • 1970-01-01
        • 1970-01-01
        • 2019-09-30
        • 1970-01-01
        • 1970-01-01
        • 2012-05-16
        • 2015-10-18
        • 1970-01-01
        相关资源
        最近更新 更多