views:

139

answers:

0

I'm facing the following challenge for a Rails project:

When a user receives mail, I want to invoke a method that writes the message out to a static file. The trick is, the mail needs to be embedded in a styled HTML page (i.e., we will surround the actual message with other page elements and style the whole page).

Here's the current approach:

1) Configure qmail to invoke a script every time said user receives email. This script simply calls ActionMailer::receive() and passes in the raw message.

2) In ActionMailer::receive(), write the styled HTML file to disk.

Here's the problem: ActionMailer::receive(), as a model, cannot access render() or render_to_string().

How else can I write a styled HTML page to disk, that contains details from the email, without duplicating the presentation code for the email? (This presentation code needs to get invoked elsewhere, too.)

We need to use render_to_string(). We have a Javascript method that resizes elements, and if we use a partial, the method definition doesn't get incorporated into the outer page and therefore never gets invoked. Other solutions seem to rely solely on rendering partials after creating an ActionBase::View instance.