Learn Building a Sitemap in Rails from Scratch for Heroku

with codediode


Designing a Sitemap for Rails without Gems

Dynamic sitemaps are very easy to build in rails and can vastly improve your organic SEO.  In just 10 minutes, your web application can have a dynamic sitemap that is always up-to-date. 

Let me first give props to the sitemap_generator gem. This is a great project and useful in many situations, but sometimes it’s better to just build your sitemap from scratch. One of the biggest drawbacks is that it can’t be used on Heroku, unless you want to host the sitemap on a cloud service like S3 with carrierwave and fog - that’s at least 3 new gems just for a sitemap. To me, this seems like a lot of overhead for a relatively minor concern. In this lesson, I’ll show you how to build a simple sitemap without any external dependencies. We will also setup an simple rake task to ping Google or any other search engine. 

Here's What We're Going to Code

  1. A Ruby on Rails view and controller that will format XML to match Google's sitemap guidelines. 
  2. A custom rake task to ping google when our sitemap changes.

Other Important Info

  • This tutorial uses Rails 4.2 and Ruby 2.2 (but works with any version of rails 4+)
  • You should know the basics of Rails before starting this lesson. 
  • I'm offering this lesson for free!

Correct XML Format for Sitemaps

According to Google’s Sitemap guidelines, this is the preferred XML markup for a sitemap. 

<?xml version=“1.0” encoding=“UTF-8”?>
<urlset xmlns=“http://www.sitemaps.org/schemas/sitemap/0.9”> 

Creating the XML Sitemap Controller and Views in Rails

This Section is Locked!

Unlock this lesson for free to view all sections.

Rake Task to Ping Google or Other Search Engines

This Section is Locked!

Unlock this lesson for free to view all sections.

Signup and Unlock for free




Years later, and I was still able to implement this in a Rails 5.1 app. Thank you.

Av 0 74a870efc51d61dcf45c95a53df6dcc47ab8a5454eb74082537ac6610a75b2ac


Worked great. Just implemented this in my rails app and it built the sitemap just as expected. I was also glad to see it was accepted by google without warnings or issues. Thanks.

Av 2 4cf64c0e1b3355a4a2080590bb0e1ed92560cfa2d71950969066908e15a100d8
a 100.0%
Technology Code

  • 35 Unlocks
  • 997 Total Reads
  • 16 minutes Est. Learning Time
Top Rated
Top Seller