我对 Rails 4.1.6 邮件预览有问题。
我想在预览模式下查看附加的图像,但它不起作用。我认为这是不正确的
有我的代码:
邮件文件
class AppMailer < ActionMailer::Base
default from: "[email protected] /cdn-cgi/l/email-protection"
# AppMailer.test_mail.deliver
def test_mail
attachments.inline['rails.png'] = File.read(Rails.root.join('app', 'assets', 'images', 'rails.png'))
mail(
to: '[email protected] /cdn-cgi/l/email-protection',
subject: "test letter",
template_path: "mailers",
template_name: "test"
)
end
end
预览文件
class MailerPreview < ActionMailer::Preview
def app_mailer
AppMailer.test_mail
end
end
模板文件
%p Hello, World!
%p= image_tag attachments['rails.png'].url
当我去
/rails/mailers/mailer/app_mailer
我看到预览页面,但图像不起作用。结果是html代码
<p>Hello, World!</p>
<p><img src="cid:[email protected] /cdn-cgi/l/email-protection"></p>
所以。我想,我应该找到一种方法来获取路径/到/文件而不是预览模式下的 CID
(当我将信发送到我的邮箱时 - 信看起来不错)
我在预览模式下做错了什么?