我正在Rails上编写一个网站,我需要芦苇RSS饲料。该脚本按预期工作,但我收到一个错误,指示无法读取源文件。检查源是否存在
这是脚本:
def setup_feed
source = "http://path_to_feed/"
content = "" # raw content of rss feed will be loaded here
open(source) do |s|
content = s.read
end
@rss = RSS::Parser.parse(content, false)
end
我担心的是,该网站将产生错误或只是“死机”如果源不提供任何理由。我该如何保护自己免受这种伤害呢?
这是确切的错误:
Errno::ENOENT in WelcomeController#index
No such file or directory - http://path_to_feed/
我不能让URI解析器工作,但我添加了救援位,它似乎照顾了错误。谢谢 – Frank 2011-04-06 11:01:06