无法让我的图像显示在 Rails Mailer 中

Can't get my images to show in Rails Mailer

我想在开发模式下测试我的电子邮件,但我无法显示图像。

在我的邮件视图中,我这样称呼它们:

<%= image_tag("how-icon-3.png", width: "101", border: "0", style: "display: block; width: 101px;", alt: "Decorissimo - Como 1") %>

我也试过

<%= image_tag("/assets/how-icon-1.png", border: "0", style: "display: block; width: 101px;", alt: "Decorissimo - Como 1") %></a>

<table border="0" width="100%" cellpadding="0" cellspacing="0" bgcolor="dce0ec" style="background: url(<%= image_path('/mailers/user_bg.jpg') %>); background-size: cover; background-position: top center; background-repeat: no-repeat;" class="main-bg">

None 个显示出来,并在 HTML 中打印,如下所示:

<img alt="Decorissimo - Como 1" border="0" src="//localhost:3000/assets/how-icon-1.png" style="display: block; width: 101px;">

我在development.rb中配置:

config.action_mailer.asset_host = 'localhost:3000'

我错过了什么?

谢谢

您添加的标签 image_tag('/assets...') 结合 localhost:3000 设置为 asset_host 意味着您在电子邮件中的所有 assets/images 都符合来自:

http://localhost:3000/assets/how-icon-3.png

这永远不会在电子邮件中呈现,因为您的电子邮件应用程序无法呈现来自 localhost:3000 的内容(无法访问它)。

在生产服务器上,我的感觉是 asset_host 是一个真正的 URL,可以在网络上解析(即 http://example.com/assets/etc)。

对于开发,您可以使用像 MailCatcher 这样的 gem 在本地捕获您的电子邮件并查看图像等。

希望对您有所帮助!