views:

129

answers:

2

Hi Everyone,

I have successfully created an email that sends on creation of a Kase, but now I need to attach a PDF that is created on the fly by Prawn and Prawno. Basically when you visit a kase such as application.com/kase/1 you just append the URL with .pdf i.e. application.com/kase/1.

I spent ages getting the PDF to work and look how I wanted, but I can't figure out how to add the PDF to an auto sending email - mainly because I cannot work out how to give it a link as it's auto generated.

Has anyone ever managed to get this to work?

Thanks,

Danny

+1  A: 

I suppose it would be better if you store generated pdf somewhere - for caching purposes, etc. But with current configuration, you can read generated page with Net::HTTP and attach response:

require 'net/http'

def your_mailer_method(record)
  #...
  attachment "application/pdf" do |a|
    a.body = Net::HTTP.get('yourdomain.com', "/kase/#{record.id}.pdf")
    a.filename="your_pdf_name.pdf"
  end  
end
Voyta
This is the bit I don't understand. Where you have /kase/1.psd the number 1 is the Kase ID which will change everytime. Is there a way around this?
dannymcc
Pass your record as a parameter to mailer method and use it's id. See edited answer.
Voyta
+2  A: 

You really should consider just not using Prawnto, and creating a subclass of Prawn::Document to do what you need. Then, in both your controller and your mailer code, it should just be:

MyReport.new.render

See the Prawn documentation on this:

http://wiki.github.com/sandal/prawn/using-prawn-in-rails

Gregory Brown