I\'m using Prawn and Prawnto to display a PDF-based reports to the user, but in some circumstances, I\'d also like to save the PDF as an attachment to one of my models. I\'m usi
I got it working without instance eval by turning it the other way around : generate the PDF in your model and render it in you controller
In a model :
def generate_pdf
Prawn::Document.new(:page_size => 'A4', :top_margin => 0, :left_margin => 0) do |pdf|
end.render
end
You can then send it as a mail attachment :
attachment = generate_pdf
mail = Notifier.send_pdf(attachment)
mail.deliver
Or render it in your browser windows in your controller :
send_data your_model.generate_pdf, :type => "application/pdf", :disposition => 'inline'