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

  • SEARCH
  • Home
  • 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

I am Generating a New Sheets using macros. For a New Sheet generation ,
Generating a random password is easy. but generating a batch is more difficult. public
When generating VS2010 targets with CMake, I would like the /LTCG flag turned on
When generating public key and then reading it with function openssl_pkey_get_public - $publicKeyResource =
I'm generating images from an original and storing them in a table. I want
I seem to be generating a lot of questions with this one little iPhone
I am generating PDFs with TCPDF, I want to save the generated pdf as
I have php generating html and I want to create layers. Basically I want
i am generating a chart map like this: http://chart.apis.google.com/chart?chs=440x220&cht=t&chco=CBD122&chld=US&chd=s:_&chtm=usa does anyone know if there
this is my first question on StackOverflow, but I think that we'll both come

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.