actionmailer with attachment created with ERB

Hi all,

I have an app that sends out a few e-mail notifications. Most of them work except for this one, which send a blank e-mail and an attached letter that was created using ERB.

    def donation_notification state, letter       recipients       subject 'Donation Notification'       from ''       body :state => state       attachment 'application/rtf' do |a|         a.body = letter         a.filename = 'letter.rtf'       end     end

The 'letter' variable is a bound ERB template that's created when I call donation_notification from my controller. Like this:

Notifier.deliver_donation_notification @state, _letter

And _letter is a partial that looks like this:

  def _letter './app/views/notifier/letter.rtf').result (binding)   end

So letter.rtf is generated fine, but the body of the e-mail is blank. I'm guessing this has to do with ERB being used by actionmailer as well. But that's only a guess, I'm not sure why this is happening.

Could anyone explain and perhaps offer a solution?

Thanks, Dave

Another thing to note. If I specify the body as a string it works:

    def donation_notification state, letter       recipients       subject 'Donation Notification'       from ''       body 'This will be seen as the e-mail's body and the attachment will come through as well!'       attachment 'application/rtf' do |a|         a.body = letter         a.filename = 'letter.rtf'       end     end

Certainly this is a work around, but not very clean.

Found my answer: