Wicked_pdf: Guidance on how to use wicked_pdf to create email attachment

Created on 25 Mar 2011  路  5Comments  路  Source: mileszs/wicked_pdf

Is there any guidance on how to attach a wicked_pdf generated doc onto an actionmailer message?

Most helpful comment

All 5 comments

From a controller, you should be able to do:

pdf = render_to_string :pdf => "some_file_name"
PdfMailer.pdf_email(pdf).deliver

And in your mailer:

# Rails3
def pdf_email(pdf=nil)
  attachments['filename.pdf'] = pdf if pdf.present?
  mail :to => '[email protected]', :subject => 'A PDF for you'
end

# Rails2
def pdf_email(pdf=nil)
  to '[email protected]'
  subject 'A PDF for you'
  attachment 'application/pdf' do |a|
    a.body = pdf
    a.filename = 'filename.pdf'
  end
end

The only problem with this is, I need to save the file... I can't do that (nor do I want to) on my server (Heroku)

Yay for random mouse accidentally closing the issue while I was typing. Had a full post written, too.

Anyway, I don't fully understand. You asked about sending a pdf in an email with actionmailer. This doesn't save to the filesystem unless you are using headers or footers, and even then it uses tempfile, which is supported on Heroku.

Here's an example app built for working on Heroku:
http://jordan.broughs.net/archives/2010/05/easy-pdf-generation-on-heroku
https://github.com/jordan-brough/heroku-pdf

This functionality (render a pdf and attach it to an email with actionamailer on the fly) is just what I'm trying to figure out... Any way you could explain in a bit more detail about how to make that work?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

douglasep picture douglasep  路  4Comments

gregblass picture gregblass  路  4Comments

m-andreas picture m-andreas  路  5Comments

BlakeWard picture BlakeWard  路  3Comments

thomasbalsloev picture thomasbalsloev  路  3Comments