2012-04-13 94 views
5

我想添加附件到通过设计(徽标图像)重置密码时发送的电子邮件,并且还想使用用户的区域设置来定位电子邮件文本。 任何人都可以帮助并告诉我要重写什么来执行此操作吗?设计用于重置密码的邮件模板

回答

6

您需要的标志图像添加为附件。

为此,请按照链接中的说明来替代默认设计::梅勒: 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

+0

但我不能以这种方式添加图像。当我尝试去做时,我只收到不好的链接。我必须在邮件中添加附件 - 我该怎么做? – 2012-04-17 14:42:54

0

我对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