I’m writing a website in Rails and I need to reed a RSS feed. The script works as intended, but I just got an error indicating that the source could not be read.
This is the script:
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
My concern is that the site will produce an error or just “crash” if the source isn’t available for whatever reasons. How can I protect myself against this?
This is the exact error:
Errno::ENOENT in WelcomeController#index
No such file or directory - http://path_to_feed/
EDIT
Found a more recent link: http://binarysoul.com/blog/rails-3-url-validation by Eric Himmelreich