Hey guys, first post here, hope you can help me.
We generate a newsletter automatically every 24 hours using the rake task. There is a section at the top of the newsletter where the administrator can post a customized message. The screen that the administrator uses has a live preview of the newsletter (they were persistent in this) displayed using a partial haml that accepts the collection.
In order to generate and send emails, we send XML documents to a third-party API that contains (among other things) HTML for the letter we would like to generate.
What I want to do is to save the result of this partial part of haml as part of the rake task, something similar to the PHP ob _ * () buffering function. Is there a way to do something like the following:
ob_start();
render :partial => newsletter, :collection => posts
newsletter_html = ob_get_contents()
xml = "
<Creative>
<Name>Our Newsletter -- #{Time.now.strftime('%m/%d/%Y')}</Name>
<HTML><html><body>#{newsletter_html}</body></html></HTML>
...
</Creative>"
I probably lack something obvious, and I could think of several ways to do this, but most of them are NOT DRY, and I don’t want to generate a lot of html in helpers, models or the task itself.
Let me know if I have a way to do this. Thanks.
source
share