Dynamic Sitemaps is a plugin for Ruby on Rails that enables you to easily create flexible, dynamic sitemaps. It creates sitemaps in the sitemaps.org standard which is supported by several crawlers including Google, Bing, and Yahoo. If the sitemap has more than 50.000 urls – or whatever you set it to using per_page – the plugin will automatically split the sitemap into smaller chunks and generate a sitemap index, also specified at sitemaps.org.


In Rails 3:

$ rails plugin install git@github.com:lassebunk/dynamic_sitemaps.git


Start by generating initializer and route:

$ rails generate dynamic_sitemaps sitemap.xml

In config/initializers/sitemap.rb:

Sitemap::Map.draw do

  # default page size is 50.000 which is the specified maximum at http://sitemaps.org.
  per_page 10

  url root_url, :last_mod => DateTime.now, :change_freq => 'daily', :priority => 1


  Product.all.each do |product|
    url product_url(product), :last_mod => product.updated_at, :change_freq => 'monthly', :priority => 0.8


  autogenerate  :products, :categories,
                :last_mod => :updated_at,
                :change_freq => 'monthly',
                :priority => 0.8


  autogenerate  :users,
                :last_mod => :updated_at,
                :change_freq => lambda { |user| user.very_active? ? 'weekly' : 'monthly' },
                :priority => 0.5


Then go to yourdomain.com/sitemap.xml in your browser.

Installing the sitemap

In public/robots.txt:

Sitemap: http://yourdomain.com/sitemap.xml

This will enable crawlers to find your sitemap.

Submitting the sitemap to crawlers


  1. Go to Google Webmaster Central at www.google.com/webmasters/ and sign in

  2. Click “Add a site…” and follow instructions for adding your site and verify ownership

  3. Go to Site configuration > Sitemaps and click “Submit a Sitemap”

  4. Type in sitemap.xml – no domain is needed as this is locked to your current website

  5. Click “Submit Sitemap”

Google will now download and use your sitemap.


Go to Webmaster Tools at www.bing.com/toolbox/webmasters/ and follow instructions.


Go to Site Explorer at siteexplorer.search.yahoo.com/ and follow instructions.

Copyright © 2010-2011 Lasse Bunk, released under the MIT license