Validating RSS Feeds in Rails

Rails1

Rails1FeedValidator is a gem which validates the RSS feeds through SOAP protocol of the W3C Feed Validation service. It helps to find out errors in RSS or ATOM feeds. In Rails app we can do the feed validation by installing the gem.

    Step#1

  • Install the FeedValidator as a gem:
  • gem feedvalidator

    Run the bundler to install the gem
    Step#2

  • Include the require ‘feed_validator’ into your controller
  • Step#3

  • Generate 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
    site_url = params[:feed][:title].sub(/(\/)+$/,'')
    begin
    v = W3C::FeedValidator.new
    if v.validate_url(site_url) && v.valid?
    @feed = Feed.new(:title => site_url)
    @feed.save
    end
    rescue
    # Do nothing
    end
    redirect_to request.referrer
    end

Leave a Reply