Using Sitemap plugin for Rails

If you have a web site and you want search engined to index your site properly you need to have sitemap for your site. Sitemap is a way to describe your web site, revealing all the static and dynamic links within your website.

I have recently been building a web site based on ROR and I was looking for a plugin to accomplish this. The plugin I used is queso/sitemap from http://github.com/queso/sitemap/tree/master. This link has instructions and also the readme with the plugin gives enough information to install this plugin. The problem I faced was with setting up widgets and the static link in the sitemap_settings link.

Since I am new to Ruby on Rails it took me a while to figure out how to setup the widgets and static link in the sitemap_settings url.  To explain how I had setup the sitemap I am going to use  the model “Term” as an example. Basically I needed Sitemap to display the url of list of terms http://www.mydomain.com/terms and all the individual terms like http://www.mydomain.com/terms/term1, http://www.mydomain.com/terms/term2 etc.

In the Widgets setting screen I added a widget named Term and entered the information as shown in the image below. The model is going to be “Term”. The named route is “terms_path” which resolves to http://www.mydomain.com/terms. Correction: The named route is “terms_url” which resolves to http://www.mydomain.com/terms. Make sure to look up your routes to see if the name route you are providing is relevant and available ( use  >> rake routes command). If you leave the finder method blank, the sitemap plugin will use find(:all) method of the model to get the list of all items in the model. Sitemap plugin is going to generate an XML comprising of the url for list of terms ( http://www.mydomain.com/terms ) and the url of individual terms (http://www.mydomain.com/terms/term1, http://www.mydomain.com/terms/term2 , etc.).

You can create a custom finder method. We have created a find_sitemap class method in the Term model as shown in the code below:

 def self.find_sitemap(*args)
    find(:all,:conditions=>['state=?','published'])
  end

 This method is going to find all terms that are in published state. One issue I ran into was the url being generated by the sitemap for the list was coming out as “/terms” instead of “http://www.mydomain.com/terms”. I had to hack the sitemap code to get this right. I had to change the code in show.xml.builder of the sitemap plugin. The code block is shown below. The following was added in line 3 in the url_for method: “root_url.chop + “. I am not sure if this is the most graceful way but I was kind of in hurry. Pardon my ignorance. There was nothing wrong with the sitemap plugin it expects a named url ( contains the entire url) instead of the path ( contains relative path). The named route in the following image should be “terms_url” instead of “terms_path”.

Sitemap Widget

Sitemap Widget

Share/Save/Bookmark

Tags: , , , , , , , , , ,

5 Responses to “Using Sitemap plugin for Rails”

  1. Richard Curran Says:

    Thanks for this, I’ll give it a shot. Not sure I follow it completely but I’ll see if I can get it working for me. Cheers

  2. spis firm Says:

    Hello there, I found your website via Google while searching for a related topic, your website came up, it looks good. I’ve bookmarked it in my google bookmarks.

  3. Kayleigh Scurci Says:

    Whilst I do not agree with all the things that you’ve stated, it’s a fascinating point of view.

  4. Héctor Damián Mosquera Benítez Says:

    Es estimulante aprender del material de otros escritores y aplicarlos. Esto hace que avancemos más rápido en nuestros propósitos. Muchas gracias por su aporte. No tiene precio.

  5. youtube xnxx Says:

    The ICRC could be the only international humanitarian agency left inside the Wanni, after
    the UN and others pulled in September, once the government stated it couldn’t guarantee their safety youtube xnxx they possess a rational expectation which they are likely to improve their flow, their rent role inside a
    short period of your energy plus they refinance that improvement every 3 or 4 years.

Leave a Reply