Save a Prawn PDF as a Paperclip attachment?

后端 未结 5 1181
悲&欢浪女
悲&欢浪女 2021-02-04 01:24

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 usi

5条回答
  •  既然无缘
    2021-02-04 02:15

    It should work if you just pass a File reference to that PDF to Paperclip.

    require 'prawn'
    pdf = Prawn::Document.new
    pdf.text("Prawn Rocks")
    pdf.render_file('/path/to/prawn.pdf')
    
    pdf_file = File.open('/path/to/prawn.pdf')
    
    # assuming your Paperclip association is named "pdf_attachment"
    my_model.pdf_attachment = pdf_file
    

提交回复
热议问题