在Rails中将HTML添加到我的RSS/Atom提要

Sha*_*ese 8 html rss ruby-on-rails builder atom-feed

默认的rails XML构建器会转义所有HTML,例如:

atom_feed do |feed|  
  @stories.each do |story|  
    feed.entry story do |entry|   
      entry.title story.title
      entry.content "<b>foo</b>"
    end  
  end  
end
Run Code Online (Sandbox Code Playgroud)

将产生文字:

<b>foo</b>
Run Code Online (Sandbox Code Playgroud)

而不是:foo

有没有办法指示XML构建器不转义XML?

Sha*_*ese 10

结果你需要做

entry.content "<b>foo</b>", :type => "html"
Run Code Online (Sandbox Code Playgroud)

虽然将它包装在CDATA中会阻止它工作.


小智 9

entry.content "type" => "html" do
    entry.cdata!(post.content)
end
Run Code Online (Sandbox Code Playgroud)