Generating Sitemaps in Rails

I am trying to generate a sitemap for my Rails app. I want to generate them on a periodic basis and not on every hit. I was previously using this to generate sitemaps . This seems good for sitemaps under 50k urls. Now I want to create an index as well and divide my sitemaps based on page types that is all school pages will go into a school sitemap similarly for other pages like student, sports etc.

2 Answers

You can do that with that same gem you mentioned. Please read Generating multiple sitemaps

And if you want to set them to check only periodically you change the <changefreq></changefreq> to something like this: <changefreq> monthly </changefreq>

Using the sitemap_generator gem will be the easiest way to do it.

Simply write your generation login in sitemap.rb file and run rake sitemap:refresh to create your sitemap for the first time.

After doing that, run this command whenever you like by writing it in the crontab or using a gem like whenever which provides a dsl for writing periodic commands using cron.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest