[英]Images in emails sent from Ruby on Rails
When I send links in an email from a Ruby on Rails application, I use the link_to
function: 当我从Ruby on Rails应用程序通过电子邮件发送链接时,我使用
link_to
函数:
<%= link_to @user.name, controller: 'users', action: 'show', id: @user.id, only_path: false %>
This will produce a link like this: 这将产生如下链接:
http://www.example.com/users/58
Or if I'm on my development environment: 或者,如果我在开发环境中:
http://localhost:3000/users/58
How do I do the same with images? 如何处理图片? I've tried:
我试过了:
<%= image_tag "/invitations/#{@invitation.id}/open.png", only_path: false %>
I was hoping to see: 我希望看到:
<img alt="Open" src="http://www.example.com/invitations/43/open.png" />
But I got this instead unfortunately: 但是不幸的是我得到了这个:
<img alt="Open" only_path="false" src="/invitations/43/open.png" />
How do I get img
tags to use the full URL based on the host I specified in my environment files? 如何根据环境文件中指定的主机获取
img
标签以使用完整URL?
您应该尝试将此配置添加到您的development.rb文件中
config.action_mailer.asset_host = "http://localhost:3000"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.