From f753de67ab5c909c437a193610beb2e7e684283f Mon Sep 17 00:00:00 2001 From: Kieran Klaassen Date: Tue, 12 Jun 2018 13:29:41 -0500 Subject: [PATCH] Add help documentation for adding to email --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 5ea32c87..8c40bcc9 100644 --- a/README.md +++ b/README.md @@ -363,6 +363,19 @@ config.middleware.use WickedPdf::Middleware, {}, except: [ %r[^/admin], '/secret ``` If you use the standard `render pdf: 'some_pdf'` in your app, you will want to exclude those actions from the middleware. + +### Include in an email as an attachment + +To include a rendered pdf file in an email you can do the following: + +```ruby +attachments['attachment.pdf'] = WickedPdf.new.pdf_from_string( + render_to_string('link_to_view.pdf.erb', layout: 'pdf') +) +``` + +This will render the pdf to a string an include it in the email. This is very slow so make sure you schedule your email delivery in a job. + ### Further Reading Mike Ackerman's post [How To Create PDFs in Rails](https://www.viget.com/articles/how-to-create-pdfs-in-rails)