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

3 Responses

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).

Continuing the Discussion

[…] 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 […]