image_tag 未使用 asset_host
image_tag in not using asset_host
在生产中,当我在邮件视图中调用 image_tag 时,图像 url 反映了我设置的资产主机。但是,当我在 lib/ 中的模块中调用 ActionController::Base.helpers.image_tag
时,它不会反映资产主机。
这是在生产环境中。
production.rb
config.action_mailer.asset_host =
config.action_controller.asset_host = Proc.new do |source|
"https://mycustomhost.com"
end
生产控制台:
irb(main):001:0>
ActionController::Base.helpers.image_tag("my_asset.jpg")
=> ...src=\"/my_app/my_asset-b00c676835d609cc1aed3ce6e7018ee1.jpg\"..
Documentation 建议我需要在 ActionController::Base
上设置 asset_host。我已经尝试在 console/setting 中设置设置 ActionController::Base.asset_host
它在 production.rb
中并重新启动 nginx,然后 运行 ActionController::Base.image_tag
,但它仍然没有 return 带有资产主机的图像 url。
有什么想法吗?
我通过从邮件程序获取 view_context
并在其上调用辅助方法来实现它。它并没有解释为什么 ActionController::Base.helpers.image_tag
没有从 asset_host
读取,但是由于我本质上是在尝试复制 ActionView
的 image_tag
的行为,所以这种方法好像好多了。
在生产中,当我在邮件视图中调用 image_tag 时,图像 url 反映了我设置的资产主机。但是,当我在 lib/ 中的模块中调用 ActionController::Base.helpers.image_tag
时,它不会反映资产主机。
这是在生产环境中。
production.rb
config.action_mailer.asset_host =
config.action_controller.asset_host = Proc.new do |source|
"https://mycustomhost.com"
end
生产控制台:
irb(main):001:0> ActionController::Base.helpers.image_tag("my_asset.jpg") => ...src=\"/my_app/my_asset-b00c676835d609cc1aed3ce6e7018ee1.jpg\"..
Documentation 建议我需要在 ActionController::Base
上设置 asset_host。我已经尝试在 console/setting 中设置设置 ActionController::Base.asset_host
它在 production.rb
中并重新启动 nginx,然后 运行 ActionController::Base.image_tag
,但它仍然没有 return 带有资产主机的图像 url。
有什么想法吗?
我通过从邮件程序获取 view_context
并在其上调用辅助方法来实现它。它并没有解释为什么 ActionController::Base.helpers.image_tag
没有从 asset_host
读取,但是由于我本质上是在尝试复制 ActionView
的 image_tag
的行为,所以这种方法好像好多了。