[LRUG] email attachments (generated from a template) in rails

Ed Davey ed at veryreal.co.uk
Wed Feb 27 07:01:29 PST 2008


Thanks but I was wanting a real attachment (which happended to be  
html and was generated on the fly from a template) rather than an  
html or multi-part email.

The solution I'm using for now is render_to_string:

my_file_to_attach = render_to_string(:action =>  
'packing_note_attachment.rhtml')

called from the controller. I then pass this string to the Mailer  
along with my other variables and attach it:

     attachment :content_type  =>  "text/html",
                :body => my_file_to_attach,
                :filename => "delivery_note_order_#{order.id}.html"

I wasn't sure about the syntax for render_to_string so for now the  
template is living in the PaymentController's views folder which  
isn't ideal, but at least it's working.

Anyone have any tips on testing attachments? Checking for presence,  
name, mimetype at least?

Thks

ED


On 26 Feb 2008, at 18:07, Andrew Stewart wrote:

>
> On 26 Feb 2008, at 18:00, Ed Davey wrote:
>
>> I have two related questions about attaching a file in rails: I want
>> to generate a delivery note in html from an rhtml template and then
>> attach it to a plain text email.
>
> Does this help?
>
> http://www.caboo.se/articles/2006/02/19/how-to-send-multipart-
> alternative-e-mail-with-inline-attachments
>
> Regards,
> Andy Stewart
>
> -------
> http://airbladesoftware.com
>
>
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org




More information about the Chat mailing list