Sitemap Generator for Ruby on Rails Applications

Follow these steps if you wish to add a sitemap.xml generator to a rails application. The idea is to generate a sitemap.xml for selected records from the database, in this case they are Articles and Categories. This sitemap is pinged to popular search engines like google, yahoo, bing and ask.

Step 1:
Add a sitemap.rb file to your lib folder. Get it from git://gist.github.com/288069.git
Make sure you replace Article and Category model by the desired models.

Step 2:
Add the following rake task:

namespace :sitemap do
  task :generate => :environment do
    sitemap = Sitemap.create!('http://www.domain.com')
  end
end

Step 3:
Schedule ‘rake sitemap:generate’ using a cron or add it to your deploy scripts.

Thats all. Every time you run ‘rake sitemap:generate’, it generates a sitemap.xml in the Rails.root/public folder and sends it to the listed search engines.

Bookmark and Share

1 Comment

RSS feed for comments on this post. TrackBack URL

  1. NITHIN STANY — 19 February, 2010

    nice one … great work

Leave a comment

Preview: