I'm using Prawn and Prawnto to display a PDF-based reports to the user, but in some circumstances, I'd also like to save the PDF as an attachment to one of my models. I'm using Paperclip for all of my attachments. Does anyone have any suggestions on how to do this?
Thanks!
It should work if you just pass a File reference to that PDF to Paperclip.
This worked for me
Where
certificate
is what my paperclip attachment is saved as in the model:@Adam Albrecht,You will be saving image as a attachment but for saving pdf as an attachment you need to add one more validation -
****validates_attachment :document, content_type: { content_type: 'application/pdf' }****
I got it working without instance eval by turning it the other way around : generate the PDF in your model and render it in you controller
In a model :
You can then send it as a mail attachment :
Or render it in your browser windows in your controller :
When using prawnto you will need to eval the variables in the .pdf.prawn template. Second step is to mimic a real file for paperclip.
Generating the PDF:
Save PDF with paperclip:
Hope this helps.