Quick Snap of Popular Ruby/RoR Blogs – an Extn of Draggable_app – I


59 sec read

We recently published a blog on Drag-n-Drop Web Components using jQuery & Rails. Now we have extended it to dynamically load blogs and tweets of popular people working with Ruby/Rails and show it in one web page.
You can quickly check the demo at http://popular-blogs.heroku.com/.

Initially we started with Ruby RSS Parser but later switched to Nokogiri as RSS Parser is not able to parse all kinds of feeds.

Click http://popular-blogs.heroku.com/ to see it live.

We used open-uri for opening the remote url and nokogiri to parse the html.
While parsing in Nokogiri we check for the tags <entry> or <item>, collect the non-nil entries or items parse through it to grab the contents.
Certain entries/items have unescaped double quotes which have been replaced by an empty string using gsub.
Here is the code snippet.
[source language=”ruby”]
#Parse the feed. Look for entry or item tag, build the html response.
#Todo: Convert to json than xml strings.
def get_info_from_feeds(feed_url)
document = Nokogiri::HTML(open(feed_url))
html_output = “”
entries = document.xpath(“//entry”)
items = document.xpath(“//item”)
data_nodes = entries.size > 0? entries : items
data_nodes[0..2].each do |item|
link = item.at(“link”).text if item.at(“link”).text.size > 2
link = item.at(“guid”).text if item.at(“guid”) && item.at(“guid”).text.size > 2
link = item.at(“link”).attributes[“href”].text if item.at(“link”).attributes[“href”]
html_output << “>
html_output << item.at(“title”).text + “

return html_output.gsub(34.chr,”)
We will soon share the entire application via github.

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *