Rails sitemap generator

Controller:

  def sitemap 
    @posts = Post.find :all, :conditions => {:private => false}
    respond_to do |format|
      format.xml  { render :layout => false }
    end    
  end

Helper:
  def w3c_date(date)
    date.utc.strftime("%Y-%m-%dT%H:%M:%S+00:00")
  end

View: sitemap.xml.builder
xml.instruct!

xml.urlset 
  "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9",
  "xsi:schemaLocation"=>"http://www.sitemaps.org/schemas/sitemap/0.9
  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd", 
  "xmlns"=>"http://www.sitemaps.org/schemas/sitemap/0.9" do
  xml.url do
    xml.loc         "http://www.sharesnippets.com"
    xml.lastmod     w3c_date(Time.now)
    xml.changefreq  "always"
  end

  @posts.each do |post|
    xml.url do
      xml.loc         url_for(:only_path => false, :controller => 'post', :action => 'show', :id => post.id)
      xml.lastmod     w3c_date(post.created_at)
      xml.changefreq  "weekly"
      xml.priority    "0.9"
    end
  end
end


route:
  map.connect "sitemap.xml", :controller => "home", :action => "sitemap"