Google Sitemaps are an effective way to let Google know which pages of your website are available for indexing. Though they go to great lengths to point out that submitting a sitemap is only a suggestion, and not a command, Google does use your sitemap to provide insights into how your website is being indexed and found by web searchers.

Here’s how I added a Google Sitemap for Moral Metric in two shakes of a lamb’s tail.

First, I made sure that my HomeController was defined as a resource in my routes.rb file:


map.resource :home

My HomeController is very sparse – it only has one public method: index. I wanted to have my application return XML when Google asked for XML, so rather than adding a new method, I used Rails’ respond_to blocks:

1
2
3
4
5
6
7
def index
  respond_to do |format|
    @things = Thing.find(:all)
    format.html {}
    format.xml {render :partial =>