【问题标题】:image_url not working within action mailer (Ruby on rails)image_url 在动作邮件程序中不起作用(Ruby on rails)
【发布时间】:2016-12-14 16:39:14
【问题描述】:

我在我的 production.rb 环境文件中添加了以下内容。

config.action_mailer.default_url_options = {host: "domain.com"}

在我看来:

<%= tag("img", src: image_url("logo.png"))  %>

但是,当我查看电子邮件中的路径时,我看到的是 image_path,而不是 URL。

http:///assets/logo.png

我做错了什么?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 views actionmailer


    【解决方案1】:

    这就是它在我的应用程序中的工作方式。试试这个

    <%= image_tag(attachments['logo.png'].url, style: 'margin: 5px') %>
    

    【讨论】:

    • 需要将其添加到邮件中: attachments.inline['logo.png'] = File.read(Rails.root.join('app/assets/images/logo.png')) ,那么你的代码就起作用了。感谢您的领导!
    • attachments['logo.png'] = File.read(data.logo.current_path) 用于动态网址。我假设你正在这样做。如果我的回答有帮助,请采纳。
    【解决方案2】:

    在生产电子邮件视图中尝试使用asset_path 而不是image_url

    【讨论】:

      【解决方案3】:

      您需要在 production.rb 中指定 config.action_mailer.asset_host = "domain.com"。然后在您的邮件视图中使用image_tag

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-06
        • 2017-11-09
        • 2013-05-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多