How to render an RSS feed in a Rails 3.x view?
-
12-12-2019 - |
Question
I have an RSS feed from Zendesk (http://mysupport.zendesk.com/forums/some-path/posts.rss) that I need to render as content on a page on my web app. What is the preferred method to pull content in like this?
At the moment I'm starting to lean to the idea that perhaps my only option is to use Nokogiri or httparty. Is there a better way? Either way, would appreciate some directions to point my horse north.
Solution
ruby has an RSS Parser built in that you can use.. This code below will cache the results for you as well, and displays the latest 4 items.
require 'rss'
Rails.cache.fetch("rss-list") do
RSS::Parser.parse(open('http://feeds.feedburner.com/your-stuff-here').read, false).items[0..4]
end
And so each item could give you a #title
and #link
(and more, obviously, like #description
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow