Skip to content

Instantly share code, notes, and snippets.

@sahidursuman
Forked from avogel3/prawn2s3.rb
Created May 29, 2019 18:24
Show Gist options
  • Save sahidursuman/aa2d30136dea1917886e1ec5909bc2f6 to your computer and use it in GitHub Desktop.
Save sahidursuman/aa2d30136dea1917886e1ec5909bc2f6 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