ActionMailer - attaching a PDF

http://pastie.org/863834

The "a.body" appears to want a string, which is why I tried render_to_string as shown in the code linked above.

This doesn't work, I get "undefined method for render_to_string".

I basically need to attach a PDF that is generated in another controller, passing 'data' as parameters for which the PDF generating engine will use.

I am able to otherwise send e-mails with ActionMailer, and generate this PDF. I just can't attach the PDF to the e-mail.

The API says it wants:   a.body = generate_your_pdf_here()

How to do I replace the "generate_your_pdf_here()" with what is produced by the action 'print_pdf' in the 'report' controller?

Any clues?

Thanks in advance!

Hey, here's an example,

def mailer_method(mymodel)   content_type "multipart/alternative"   part :content_type => "text/html", :body => mymodel.text   attachment "application/pdf" do |a|     a.filename = mymodel.pdf_filename     a.body = mymodel.pdf_render.render end

Take a look on the "content_type" header, you have to set the mail as a Multipart email, not just html.

Regards, Fernando

This definitely helps, thank you, but I still am unsure how to pass the parameters to the mymodel.pdf_render action?

The only way I know of to pass parameters is as if it were a URL, such as with:

   /mymodel/pdf_render?data=BLAH

or something like:

   :controller => 'mymodel', :action => 'pdf_render', :data => "BLAH"

How could I achieve this using the syntax you gave me?

    a.body = mymodel.pdf_render.render

Sorry for my newbieness, THANKS!

I think I got it, thanks for your help!!!