For newer ones, you really don't need to send the request again when you can:
mail.attachments["invoice.pdf"] = {:mime_type => "application/pdf" , :content => pdf_generator}
Instead of this:
send_data pdf.render , :filename => file_name_here , :type => "application/pdf"
just do this:
pdf.render , :filename => file_name_here , :type => "application/pdf"
Not send_data , just render this pdf in your email application as indicated in the first snippet.
In fact, I just wrote Gist on github.
source share