[英]Rails 4 Mailer, Amazon S3, and inline images
我在Heroku上托管了一个Rails 4应用程序,它为S3存储桶提供资源。 我正在尝试自定义我的邮件程序(在这种情况下,是Devise邮件程序的自定义),以便我可以将内嵌图像嵌入到我的电子邮件中。
根据Rails文档,邮件程序应包含以下代码:
def confirmation_instructions(record, token, opts={})
# Prepare image for embedding
attachments.inline['logo'] = File.read("#{Rails.root}/app/assets/images/logo.jpg")
# Allow Devise to do its thing
super
end
视图应包含以下内容:
<%= image_tag attachments['logo'].url, :style => "my styling here" %>
在Heroku上,这会失败并显示以下日志:
ActionView :: Template :: Error(未定义的方法`url'代表nil:NilClass):
“我的造型在这里”%>
换句话说,它看起来像attachments.inline ['logo']返回nil,然后视图在nil上调用.url。
我尝试了很多修复,在这一点上我非常恼火。 我知道它一定是简单的我忽略了,我希望那里的人可以指出我哪里出错了。
提前致谢。
尝试这个:
File.read(Rails.root.join("app/assets/images/logo.jpg")
这就是我开始工作的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.