我正在使用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
时,图像可以正常显示。
我该如何解决这个问题?
asset.url.gsub(/\?.*/, "")
作为一个快速修复方案? - cwninja