在生产中,当我在邮件 View 中调用 image_tag 时,图像 url 反射(reflect)了我设置的 Assets 主机。但是,当我在 lib/中的模块中调用 ActionController::Base.helpers.image_tag
时,它不会反射(reflect) Assets 主机。
这是在生产环境中。
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。我已经尝试在控制台中设置 ActionController::Base.asset_host
/在 production.rb
中设置它并重新启动 nginx,然后运行 ActionController::Base .image_tag
,但它仍然没有返回带有 Assets 主机的图像 url。
有什么想法吗?
最佳答案
我通过从邮件程序获取 view_context
并在其上调用辅助方法来实现它。它并没有解释为什么 ActionController::Base.helpers.image_tag
没有从 asset_host
中读取,但是因为我本质上是在尝试复制 的行为>ActionView
的image_tag
,这种做法似乎更好。
关于ruby-on-rails - image_tag 不使用 asset_host,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35192401/