Hey guys, first post here, hope you can help me out.
We're generating a newsletter automatically every 24 hours using a rake task. There's a section at the top of the newsletter where an admin can put a customized message. The screen that the admin uses has a live preview of the newsletter (they were insistent on this), rendered using a haml partial that takes a collection.
In order to generate and send the emails, we are sending xml documents to a third party API that contain (among other things) the HTML for the email that we'd like to generate.
What I want to do is save the output of this haml partial within a rake task, something similar to PHP's ob_*() buffering functions. Is there any 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'm probably missing something obvious, and I could think of a few ways to do this but most of them are not DRY and I don't want to be generating a lot of html in the helpers, models, or the task itself.
Let me know if there is a way for me to accomplish this. Thanks.