Is there an easy way to create a sitemaps file for Rails projects? Especially for dynamic sites (such as Stack Overflow for example) there should be a way to dynamically create a sitemaps file. What is the way to go in Ruby and/or Rails?
What would you suggest? Is there any good gem out there?
Add this route towards the bottom of your
config/routes.rbfile (more specific routes should be listed above it):Create the
SitemapController(app/controllers/sitemap_controller):—As you can see, this is for a blog, so is using a
Postmodel. This is the HAML view template (app/views/sitemap/index.xml.haml):That’s it! You can test it by bringing up http://localhost:3000/sitemap.xml (if using Mongrel) in a browser, or perhaps by using cURL.
Note that the controller uses the
stale?method to issue a HTTP 304 Not Modified response if there are no new posts sinces the sitemap was last requested.