Skip to content

Rails Sitemap

“When something is too hard, it means that you’re not cheating enough. it means that you’re doing it wrong“. Generating a Rails sitemap (hash of application controllers and actions) is as simple as placing and calling this method in your application:

Posted in Ruby.

3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. anonymous says

    As the name of your method states, it is only for getting controllers and their action methods. However, if you have an ERB file defined in the controller’s view directory that does not have a corresponding method in the controller class, this page will not be in the site_map hash returned by your method. So generating a site map based on the hash from this method will be incomplete.

    It wouldn’t be too hard to fix, you’d just need to have another Find.find block on the RAILS_ROOT “/app/views’ directory (making sure to ignore the layout directory and any erb files that already correspond to entries in the hash).

  2. Richard Huang says

    I wrote a sitemap rails plugin that will generate a sitemap.xml from sitemap.rb whose format is very similar to routes.rb. The home page of the sitemap plugin is

Continuing the Discussion

  1. The Learning Journey » On-Ruby Contest Winner linked to this post on January 10, 2008

    […] Eyler from On Ruby has notified me that I won his Holiday Blogging Contest. My entry for generating a Rails site map was apparently the best Rails how-to in those posted. It won me 3 books from Apress. This is my […]

Some HTML is OK

or, reply to this post via trackback.