Validate RSS or ATOM feeds using FeedValidator in Rails

FeedValidator is an interface to the W3C Feed Validation online service based on its SOAP 1.2 support. It helps to find errors in RSS or ATOM feeds. In Rails app this can be done installing the gem.

Step#1

You can install FeedValidator as a gem by writing in gem file:

gem  ‘feedvalidator’

Run   bundle install  to install the gem

Step#2

Include the require ‘feed_validator’ into your controller

Step#3

Create a migration file and edit the file to add the following fields.

class CreateFeeds < ActiveRecord::Migration
   def self.up
     create_table :feeds do |t|
       t.string :title
       t.timestamps
     end
  end

  def self.down
    drop_table :feeds
  end
end

Step#4

Validate your feed URL in your controller

 def create
    valid = false
    site_url = params[:feed][:title].sub(/(\/)+$/,'')
      begin
        v = W3C::FeedValidator.new
        if v.validate_url(site_url) && v.valid?
          valid = true
          @feed = Feed.new(:title => site_url,
          @feed.save
        end
      rescue
        # Do nothing
      end
    redirect_to request.referrer
  end

Grab RSS feeds content from blog site using jquery

Sometime we need our blog website content as a widget in website. Its a quite easy process using zRSS Feeds reader

Download the latest version of zRSS feed here

Include the jQuery and zRSSFeed libraries in your page

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&#8221; type=”text/javascript”></script>
<script src=”jquery.zrssfeed.min.js” type=”text/javascript”></script>

Add a DIV tag where you want to display the feed as widget and give it an ID

<div id=”my_blog_content”></div>

Now add the script to call the zRSSFeed plugin with the RSS URL and any options. Our example gets 10 feeds from the Reuters site.

<script type=”text/javascript”>
$(document).ready(function () {
$(‘#my_blog_content’).rssfeed(‘http://feeds.reuters.com/reuters/businessNews&#8217;, {
limit: 10
});
});
</script>

By default it returns all data with non css format . Override the css to file in your website like

<stylesheet>

#my_blog_content .rssHeader{
display:none;
}
#my_blog_content .rssBody ul{
margin:0px;
padding:0px;
}
#my_blog_content .rssBody ul li{
list-style:none;
}
#my_blog_content .rssBody ul li div{
font-size:9px;
fint-weight:bold;
}
#my_blog_content .rssBody ul li h4{
margin-bottom:3px;
}
#my_blog_content .rssBody ul li a{
color:#fff;
}
#my_blog_content .rssBody ul li a:hover{
color:#fff;
text-decoration:underline;
}
</stylesheet>

 

Complete example

In veiw file

 

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml&#8221; xml:lang=”en” lang=”en”>
<head>

<meta http-equiv=”content-type” content=”text/html; charset=utf-8″ />
<meta http-equiv=”content-language” content=”en” />

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&#8221; type=”text/javascript”></script>
<script src=”jquery.zrssfeed.min.js” type=”text/javascript”></script>

<title>Grab posts from Blog</title>

<script type=”text/javascript”>
$(document).ready(function () {
$(‘#my_blog_content’).rssfeed(‘http://feeds.reuters.com/reuters/oddlyEnoughNews&#8217;);
});
</script>
<stylesheet>
#my_blog_content .rssHeader{
display:none;
}
#my_blog_content .rssBody ul{
margin:0px;
padding:0px;
}
#my_blog_content .rssBody ul li{
list-style:none;
}
#my_blog_content .rssBody ul li div{
font-size:9px;
fint-weight:bold;
}
#my_blog_content .rssBody ul li h4{
margin-bottom:3px;
}
#my_blog_content .rssBody ul li a{
color:#fff;
}
#my_blog_content .rssBody ul li a:hover{
color:#fff;
text-decoration:underline;
}
</stylesheet>
</head>
<body>
<h4>Data</h4>
<div id=”my_blog_content”></div>
</body>
</html>