Is there any guidance on how to attach a wicked_pdf generated doc onto an actionmailer message?
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?
Here are some relevant links with further detail about attaching wicked_pdf pdfs to emails:
http://stackoverflow.com/questions/5421615/rails-3-actionmailer-and-wicked-pdf/5524221
http://stackoverflow.com/questions/5762583/rails-3-render-pdf-from-view-and-attach-to-email/5813394
Most helpful comment
Here are some relevant links with further detail about attaching wicked_pdf pdfs to emails:
http://stackoverflow.com/questions/5421615/rails-3-actionmailer-and-wicked-pdf/5524221
http://stackoverflow.com/questions/5762583/rails-3-render-pdf-from-view-and-attach-to-email/5813394