Life In The Stack Trace...

TODO: <Insert clever marketing phrase here>

Default Values

Default values and attributes are set in config/routes.rb.

MyApp::Application.routes.draw do
  title "My Rails App"              # default title for meta tags
  lastmod "02/04/2013"              # default last-modified date for sitemap and meta tags
  canonical_host ""  # default canonical host for sitemap and meta tags.

Each time the values are built for a sitemap url or meta tag for a page, the default values are used as a base. The controller in question is "asked" to provide values for defined attributes and those values are merged with the default values overwriting them. Also, if a model object is available the same process is repeated.

DuckMap defines default attributes for all values required by sitemap urls and meta tags. You can override the default attributes using one of three methods.

acts_as_sitemap - sets all values and attributes including handlers and segments.
sitemap_handler - wrapper method for acts_as_sitemap.
sitemap_segments - wrapper method for acts_as_sitemap.

Two of the methods are really just convenience methods to help reduce code clutter. All of the handlers are capable of being configured globally as well. Let's say you have a standard column on all of your tables named "tags" and it is used to store information that would work well for the keywords meta tag. You can easily tell all of the handlers within your app to use the "tags" attribute from a controller or model by using the following configuration.

MyApp::Application.routes.draw do
  acts_as_sitemap keywords: :tags

Have a look at the demo application. The areas of interest include config/routes.rb, books / trucks controllers and models.

TestCom::Application.routes.draw do

  title "my test app"

  keywords "Ruby On Rails, DuckMap"

  description "Moe Larry the Cheese..."

  changefreq "weekly"

  priority "0.8"

  lastmod "02/07/2013"

  canonical_host ""

  # tells all controllers and models to look for an attribute named :tags
  # when looking for :keywords
  acts_as_sitemap keywords: :tags

  resources :books

  resources :trucks

  root to: 'home#index'


class BooksController < ApplicationController

  # override the default global static title set via config/routes.rb
  # only for the index action
  acts_as_sitemap :index, title: "Listing of all books..."

  # the title is built using the full_title method on the book model.
  # only for the show action
  acts_as_sitemap :show, title: :full_title


class Book < ActiveRecord::Base

  def full_title
    return "#{} - #{self.title}"


class TrucksController < ApplicationController

  # the title is built using the full_title method on the book model.
  # for both index and show actions.
  acts_as_sitemap title: :full_title


class Truck < ActiveRecord::Base

  def full_title
    return "#{self.make} - #{self.model}"