Last active
August 9, 2022 17:38
-
-
Save avogel3/c9a738c7fe3dac7229b3781d946a4d72 to your computer and use it in GitHub Desktop.
Uploading Prawn Generated PDFs to S3 in Rails using Paperclip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ran into an issue recently where I wanted to use our custom prawn class to generate a PDF, then upload it to Amazon S3 using paperclip. | |
# Let 'OurCustomPdf' be our prawn class. | |
# Let the variable '@user' be our our model, has_many :documents | |
# Let 'Document' be our paperclip model, belongs_to :user | |
pdf = OurCustomPdf.new(@user, "pdf") | |
upload = @user.documents.new | |
upload.attachment = StringIO.new(pdf.render) | |
upload.save! | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment