I'm using Paperclip to allow users to attach things, and then I'm sending an email and wanting to attach the file to the email. I'm trying to read the file in and add it as an attachment, like so:
# models/touchpoint_mailer.rb
class TouchpointMailer < ActionMailer::Base
def notification_email(touchpoint)
recipients "[email protected]"
from "Touchpoint Customer Portal <[email protected]>"
content_type "multipart/alternative"
subject "New Touchpoint Request"
sent_on Time.now
body :touchpoint => touchpoint
# Add any attachments the user has included
touchpoint.assets.each do |asset|
attachment :content_type => asset.file_content_type,
:body => File.read(asset.url)
end
end
end
This gives me the following error No such file or directory - /system/files/7/original/image.png?1254497688
with the stack trace saying it's the call to File.read
. When I visit the show.html.erb
page, and click on the link to the image, which is something like http://localhost:3000/system/files/7/original/image.png?1254497688
, the image is displayed fine.
How can I fix this problem?