render_to_string from a rake task

Posted by Horace Loeb on Stack Overflow See other posts from Stack Overflow or by Horace Loeb
Published on 2010-04-12T04:04:45Z Indexed on 2010/04/12 4:13 UTC
Read the original article Hit count: 485

Filed under:
|

I want to use a Rake task to cache my sitemap so that requests for sitemap.xml won't take forever. Here's what I have so far:

  @posts = Post.all

  sitemap = render_to_string :template => 'sitemap/sitemap', :locals => {:posts => @posts}, :layout => false
  Rails.cache.write('sitemap', sitemap)

But when I try to run this, I get an error:

undefined local variable or method `headers' for #<Object:0x100177298>

How can I render a template to a string from within Rake?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about rake