我在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):
“我的造型在这里”%&gt;
换句话说,它看起来像attachments.inline ['logo']返回nil,然后视图在nil上调用.url。
我尝试了很多修复,在这一点上我非常恼火。我知道它一定是简单的我忽略了,我希望那里的人可以指出我哪里出错了。
提前致谢。
答案 0 :(得分:2)
试试这个:
File.read(Rails.root.join("app/assets/images/logo.jpg")
这就是我如何让它发挥作用。