Ten*_*ack 3 email ruby-on-rails actionmailer ruby-on-rails-3
我知道你可以在Rails 3中添加一个图像作为电子邮件的附件
def email_image(email)
attachments["img"] = File.read('/path to image')
mail(:to => email)
end
Run Code Online (Sandbox Code Playgroud)
但有没有办法从网址附加图像而不是本地保存的图像?我想附上一个用回形针保存在S3上的图像.有没有一种简单的方法可以做到这一点,还是我需要先下载图像?
你需要
require 'open-uri'
Run Code Online (Sandbox Code Playgroud)
然后呢
attachments["filename"] = open(url-to-image).read
Run Code Online (Sandbox Code Playgroud)