DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

RSS Feed In .rxml Template

05.22.2005
| 9045 views |
  • submit to reddit
        
xml.rss('version' => '2.0') do
  xml.channel do 
    xml.title(page_title)
    xml.link(@request.protocol + @request.host_with_port + url_for(:rss => nil))
    xml.description(page_title)
    @posts.each { |p|
      xml.item do 
        xml.title(p.title)
        xml.link(@request.protocol + @request.host_with_port + url_for(:controller => "posts", :action => "show", :id => p.id))
        xml.description(niceify_html_for_rss(p.content))
        xml.pubDate(p.updated_at)
      end
    }
  end
end
    

Comments

Philipp M replied on Tue, 2007/01/23 - 1:47am

RSS expects dates formatted according to RFC 822, so instead of xml.pubDate(p.updated_at) use xml.pubDate(p.updated.at.rfc822)

Snippets Manager replied on Mon, 2012/05/07 - 2:12pm

Oh, it's something that just knocks out the HTML, etc. In that case HTML wasn't required.

Snippets Manager replied on Mon, 2006/04/17 - 6:24am

What is "niceify_html_for_rss"?

Snippets Manager replied on Mon, 2012/05/07 - 2:12pm

And instead of xml.pubDate(p.updated_at) this would be better: xml.pubDate(CGI.rfc1123_date p.updated_at)

Snippets Manager replied on Mon, 2012/05/07 - 2:12pm

What is "niceify_html_for_rss"?