Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在RubyonRails项目中解析RSS会将html显示为内联html_Html_Ruby On Rails_Ruby On Rails 3_Rss - Fatal编程技术网

在RubyonRails项目中解析RSS会将html显示为内联html

在RubyonRails项目中解析RSS会将html显示为内联html,html,ruby-on-rails,ruby-on-rails-3,rss,Html,Ruby On Rails,Ruby On Rails 3,Rss,我在视图中使用调用我的提要,在我的助手中有一个小片段 require 'rss/1.0' require 'rss/2.0' require 'open-uri' def blog_feed source = "http://www.domain.com/.rss" # url or local file content = "" # raw content of rss feed will be loaded here open(source) do |s| cont

我在视图中使用
调用我的提要,在我的助手中有一个小片段

require 'rss/1.0'
require 'rss/2.0'
require 'open-uri'

def blog_feed
    source = "http://www.domain.com/.rss" # url or local file
    content = "" # raw content of rss feed will be loaded here
    open(source) do |s| content = s.read end
    rss = RSS::Parser.parse(content, false)

    html = "<ul>"
    rss.items.first(3).each do |i|
    html << "<li><a href='#{i.link}'>#{i.title}</a></li>"
    end
    html << "</ul>"
    html


  end
需要“rss/1.0”
需要“rss/2.0”
需要“打开uri”
def blog_提要
来源=”http://www.domain.com/.rss“#url或本地文件
content=”“#rss源的原始内容将加载到此处
开放(源代码)do | s | content=s.read end
rss=rss::Parser.parse(内容,false)
html=“
    ” rss.items.first(3).每个do | i|
    html您在视图中处理和显示RSS的方式与我的方式不同,但快速的回答是,对于以这种方式构建的任何html字符串,您都需要调用html\u safe

    这可能是不安全的,因为传入的RSS数据中可能包含导致跨站点安全问题的代码。您可以使用清理帮助程序来处理此问题。我认为清理助手会自动为您调用html\u safe

    因此,在blog_feed方法的末尾,将html返回值替换为:

      sanitize html
    
    请在此处查看有关消毒的文档: