如何为邮件程序中的 public 文件夹生成 url?

how to generate url for public folder in mailers?

在邮件程序模板中,我想为路径 public/system/test.png

生成正确的 url

假设在邮件模板中

 <%= link_to k, "/system/test.png" %> <br />

如何生成完整路径,例如

https://www.example.com/system/test.png

感谢您的帮助!谢谢!

试试这个:

<%= link_to k, root_url + 'system/test.png' %>

您可以在 production.rb

中添加资产主机
config.action_controller.asset_host = 'https://www.example.com'

你可以罚款更多关于资产here

你可以使用 <%= link_to k, "#{Rails.root}/system/test.png" %> 希望这就是您要找的。

<%= link_to k, asset_url('/public/system/test.jpeg')%>

这将生成 link 作为:-

https://example.com/public/system/test.jpeg

并且您的 html 代码将生成如下所示:--

<a href="https://example.com/public/system/test.jpeg">k</a>

尝试以下

此代码已经过测试

<%= link_to image_tag("/system/test.png"), root_url %>

image_tag 默认位于 public 文件夹,点击图片后 root_url 将重定向到主页

或者方案二

<a href="<%= root_url %>">
    <%= image_tag "#{Rails.root}/public/system/test.png" %>
</a>