cannot get correct pdf attachment file url

98 views
Skip to first unread message

erwin

unread,
Mar 13, 2012, 9:45:02 AM3/13/12
to Paperclip Plugin
[Rails 3.2.2, Ruby 19.3, Paperclip 2.7.0]

I have a standard paperclip attachment in my Estimate model


has_attached_file :pdf_attachment,
:default_url => "/logos/pdficon_large.png"

in dev mode , all attachments are correctly stored into /public/
system/:attachment/:id/:style/:filename

I am trying to send these file as email attachment using Mailer
setup :
...
file_name = @estimate[:pdf_attachment_file_name]
file_path = @estimate.pdf_attachment.url
attachments[file_name] = File.open(file_path, 'rb'){|f| f.read}

but as the file_path is /system/pdf_attachments/22/original/
Devis_2012-22.pdf, I get an error on File open...

(No such file or directory - /system/pdf_attachments/22/original/
Devis_2012-22.pdf

Q : should I modify the Paperclip path ? or should I modify the
file_path for the File open ?

thanks for your feedback



erwin

unread,
Mar 13, 2012, 6:31:12 PM3/13/12
to Paperclip Plugin
I found a way to do it, (at least in dev mode.. not yet tested in
production ..)

using the path and not the url.... is that correct ? can anyone
confirm it ? thanks

file_path = Pathname.new(@estimate.pdf_attachment.path)
attachments[file_name] = File.open(file_path, 'rb'){|f| f.read}



Reply all
Reply to author
Forward
0 new messages