Paperclip を使用してユーザーが添付できるようにしてから、メールを送信してファイルをメールに添付したいと考えています。次のように、ファイルを読み込んで添付ファイルとして追加しようとしています。
# models/touchpoint_mailer.rb
class TouchpointMailer < ActionMailer::Base
def notification_email(touchpoint)
recipients "me@myemail.com"
from "Touchpoint Customer Portal <portal@touchpointclients.com>"
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
これにより、次のエラーが発生No such file or directory - /system/files/7/original/image.png?1254497688
し、スタック トレースが への呼び出しであることが示されFile.read
ます。ページにアクセスしてshow.html.erb
、 のような画像へのリンクをクリックするとhttp://localhost:3000/system/files/7/original/image.png?1254497688
、画像が正常に表示されます。
この問題を解決するにはどうすればよいですか?