26 August 2010

Scream SEO Karma with a Google Sitemap for your Rails Blog

Handwritten by TVD

Recently, I advised a client on what I consider the top three Google services for his next social media project. Today I want to talk about a fourth Google service I think is helpful, but certainly not mandatory: Google Sitemaps.

Think about it, you’ve spent hours toiling away at your next awesome blog post. Why not help Google find that content it might not have found otherwise? Typically you have to manually build the sitemap. Then you have to manually submit the sitemap to Google. Who has time for all of that?

Rails Google Sitemap Code

Dynamically create a sitemap for your blog the Rails way.
I know some of you are anxious to jump into the code, so let’s get to it:

####config/routes.rb

Create the following Rails route:

map.sitemap'sitemap.xml',:controller=>'sitemap'

UPDATE: Above route was written for Rails 2.3.8. Here is the updated route for Rails 3.0. Remaining code is Rails 3.0 complaint:

match'sitemap',:to=>'sitemap#index',:via=>[:get]

####app/controllers/sitemap_controller.rb

Create the following Rails controller to serve the Google sitemap requests:

Do pay attention to the /user/bin/curl directive. You must give the absolute path to your instance of curl. Also, I don’t want to handle any responses from Google, so I send any responses to /dev/null. Think of /dev/null as a black hole where data goes in and is never stored or seen again!

Good luck with your next social media venture. And remember to take some time to have fun with it!

discuss on twitter

every day thousands of developers use our charts & gauges to get the job done right