【问题标题】:Rails 3.1 Assets in ActionMailer with image_tag带有 image_tag 的 ActionMailer 中的 Rails 3.1 资产
【发布时间】:2011-11-12 17:38:37
【问题描述】:

资产在我的 Web 视图中运行良好,但由于某种原因,我的 Mailer 没有使用资产管道。我正在尝试在我的邮件视图中使用 image_tag:

=link_to image_tag("logo.png")

但是,它呈现为

<img alt="logo" src="http://mydomain.com/assets/logo.png">

而不是

<img alt="logo" src="http://mydomain.com/assets/logo-xxxxxxxxx...png">

我错过了什么吗?

我的设置是:

config.action_mailer.default_url_options = { :host => config.domain }
config.action_mailer.asset_host = "http://" + config.domain

谢谢!

【问题讨论】:

  • 你有没有想过这个问题?我知道已经快 3 年了,但我遇到了同样的问题 :)
  • 嘿看那个!又冲进去了!我真的在服用疯狂的药片吗?这对其他所有人都有效,对吧?

标签: ruby-on-rails actionmailer asset-pipeline


【解决方案1】:

尝试在您的邮件模板中放入以下内容而不是 link_to(link_to 没有任何意义,因为您在此处将图片链接到任何内容,而且我没有看到 a href 作为您的 html 中的输出):

= asset_path("logo.png")

也放入你的特定环境文件:

config.action_mailer.default :content_type => "text/html"

这样,您可以确定始终使用 HTML 作为默认内容类型。如果你在邮件中使用图片,最好把它写成 html。

【讨论】:

    猜你喜欢
    • 2012-02-08
    • 1970-01-01
    • 2017-06-07
    • 1970-01-01
    • 2012-02-04
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多