Skip to content

Instantly share code, notes, and snippets.

@avogel3
Last active August 9, 2022 17:38
Show Gist options
  • Save avogel3/c9a738c7fe3dac7229b3781d946a4d72 to your computer and use it in GitHub Desktop.
Save avogel3/c9a738c7fe3dac7229b3781d946a4d72 to your computer and use it in GitHub Desktop.
Uploading Prawn Generated PDFs to S3 in Rails using Paperclip
# 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