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

时间:2020-03-06 14:28:20  来源:igfitidea点击:

默认的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

将产生文本:

<b>foo</b>

代替:foo

有什么方法可以指示XML构建器不要转义XML?

解决方案

原来你需要做

entry.content "<b>foo</b>", :type => "html"

尽管将其包装在CDATA中会使其停止工作。

http://builder.rubyforge.org/classes/Builder/XmlMarkup.html

The special XML characters <, >, and & are converted to <, > and & automatically. Use the << operation to insert text without modification.