邮件中的image_tag不使用asset_host

Rya*_*nJM 55 actionmailer ruby-on-rails-3

image_tag没有使用我设置的asset_host.有什么想法吗?我能想到的唯一一件事就是它与梅勒有关.

配置/环境/ development.rb

config.action_controller.asset_host = "http://localhost:3000"
Run Code Online (Sandbox Code Playgroud)

myMailer.rb

<%= image_tag "logo.png", :style=>"margin-left:10px; padding-bottom:15px;" %>
Run Code Online (Sandbox Code Playgroud)

呈现为:

<img alt="Logo" src="/images/logo.png?1303090162" style="margin-left:10px; padding-bottom:15px;" />
Run Code Online (Sandbox Code Playgroud)

在控制台中:

> MyApp::Application.config.action_controller
#<OrderedHash {… :asset_host=>"http://localhost:3000", …}>
Run Code Online (Sandbox Code Playgroud)

我需要image_tag来创建完整路径网址,因为它会显示在电子邮件中.

Pat*_*son 93

我之前错了.这是您需要的解决方案(直到rails 3.1,其中asset_host配置变得统一):

config.action_mailer.asset_host = "http://localhost:3000"
Run Code Online (Sandbox Code Playgroud)

  • 至少在Rails 3.2中有一个快捷方式:`config.asset_host ='localhost:3000'`.它设置`config.action_controller.asset_host`和`config.action_mailer.asset_host`. (17认同)
  • 铁轨4似乎仍然需要这样. (6认同)
  • 它似乎没有统一.在Rails 3.2.8上,我仍然需要将它分别设置为`action_controller`配置. (4认同)
  • 即使在 Rails 5 中仍然是必要的。 (2认同)

Tia*_*nco 22

我们需要在Rails 3.1和3.2上指定config.action_controller.asset_host和config.action_mailer.asset_host.

要在两个电子邮件和非电子邮件视图中将主机名添加到image_tag,请将以下内容添加到您的环境文件中:

config.action_controller.asset_host = 'http://localhost:3000'
config.action_mailer.asset_host = config.action_controller.asset_host
Run Code Online (Sandbox Code Playgroud)

其中'http:// localhost:3000'应替换为您的主机URL(如果适用,则为端口).

这需要在action_controller和action_mailer上设置,即使在Rails 3.2.x中也是如此.