Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 330171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:39:24+00:00 2026-05-12T09:39:24+00:00

We are generating a newsletter automatically every 24 hours using a rake task. There’s

  • 0

We are 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>&lt;html&gt;&lt;body&gt;#{newsletter_html}&lt;/body&gt;&lt;/html&gt;</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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:39:24+00:00Added an answer on May 12, 2026 at 9:39 am

    A common way to do this (which is typically advised against) is to render into a string in your model or rake task:

    
    cached_content = 
      ActionView::Base.new(Rails::Configuration.new.view_path).render(:partial => "newsletter", :locals => {:page => self,:collection => posts})
    

    see here for a more full description:
    http://www.compulsivoco.com/2008/10/rendering-rails-partials-in-a-model-or-background-task/

    If you are using page or fragment caching, you could pull the content out of the cache. The easiest way to do this is to just enable caching, and then look at where the files are being placed.

    http://guides.rubyonrails.org/caching_with_rails.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building a module for generating HTML for email newsletters. We've looked into using
While generating charts using RS 2008 betas, RC0 and such., I never specified any
I've been using a system with imagettftext for a while now to add nog
Generating a truly random string of a given length is a fairly straightforward (and
Generating inline JavaScript in HTML has always made me feel dirty and after having
Generating normal columnar data in excel file is quite easy but does any one
When generating graphs and showing different sets of data it usually a good idea
When generating setters and getters in Eclipse one of the options is to use
When generating Java from an XSD via the XJC compiler, I always get the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.