How do I get the file path from my ActionMailer?
I'm developing a Rails 3 application, and I currently I would like to add an image as an attachment into an email.
I'm doing the following right now:
class CouponMailer < ActionMailer::Base
default :开发者_如何学Gofrom => "name@domain.com", :content_type => "multipart/mixed"
def send_coupon(recipient, coupon)
@coupon = coupon
@recipient = recipient
attachments.inline["#{coupon.picture.title}"] = File.read(File.join(root_url, coupon.picture.url))
mail(:to => recipient.email, :subject => "a subject")
end
end
The image I want has been uploaded from my RefineryCMS application, and when I copy the url that I get when I do File.join(root_url, coupon.picture.url)
and paste it in the browser, I can see the imagen, but when I run the application I get the following error:
No such file or directory - http://localhost:3000/system/images/BAhbBlsHOgZmIiwyMDExLzA1LzI0LzE3XzQ4XzUxXzcxNF9tYWluX2ltYWdlMi5qcGc/main_image2.jpg
Any ideas?
It looks like RefineryCMS is using Dragonfly for file uploads. I believe you want to call .path on your picture to retrieve a file system path. Probably something like so:
attachments.inline["#{coupon.picture.title}"] = File.read(coupon.picture.file)
Have a look at the documentation for more info. You should find what you need on the General Usage page.
精彩评论