【发布时间】:2012-04-13 14:51:39
【问题描述】:
我想在通过设计(徽标图像)重置密码时发送的电子邮件中添加附件,并且我想使用用户的区域设置来本地化电子邮件文本。 谁能帮助并告诉我要覆盖什么来做到这一点?
【问题讨论】:
我想在通过设计(徽标图像)重置密码时发送的电子邮件中添加附件,并且我想使用用户的区域设置来本地化电子邮件文本。 谁能帮助并告诉我要覆盖什么来做到这一点?
【问题讨论】:
您需要将徽标图像添加为附件。
为此,请按照链接中的说明覆盖默认的 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') %>
【讨论】:
只需运行rails generate devise:views 并在app/views/devise/mailer/reset_password_instructions.html.erb 中编辑模板
【讨论】:
我正在为 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
【讨论】: