Skip to content

Instantly share code, notes, and snippets.

@afeld
Created December 12, 2011 20:47
Show Gist options
  • Save afeld/1469020 to your computer and use it in GitHub Desktop.
Save afeld/1469020 to your computer and use it in GitHub Desktop.
using HTML in a RSS feed in Rails
<h1><%= record.name %></h1>
<!-- etc -->
@records.each do |record|
xml.item do
xml.title record.name
xml.description do
desc = render :partial => 'body', :locals => {:record => record}
desc = simple_format desc # preserves newlines by converting to <p> tags
xml.cdata! desc # wrap the HTML content in CDATA tags
end
end
end
@oleoneto
Copy link

Stumbled upon this recently. I was running into this: MissingTemplateException. The error looked like such:

Missing partial _body with {:locale=>[:en], :formats=>[:rss], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}

Two options to address this exception:

  1. Rename _body.html.erb to _body.rss.erb or
  2. Pass :formats to render, like so render :partial => 'body', :locals => { :record => record }, :formats => [:html]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment