Life In The Stack Trace...

TODO: <Insert clever marketing phrase here>

Route Filters

Filters give you the power to control the contents of a sitemap based on verbs, controller name, action name, and route name. The default configuration is to exclude everything except routes that have an action name of :index or :show. For most Rails apps, that should cover the general needs of generating a sitemap.

You can apply route filters using two methods: - Using exclude and include statements within a sitemap block. - Using exclude and include statements directly on the route.

MyApp::Application.routes.draw do

  # within the default sitemap block
  # exclude all "show" actions from all routes.
  exclude_actions :show

  root to: 'home#index'
  resources :contact

  # directly on the route.
  # re-include :show action for faqs
  resources :faqs, include_actions: :show

  # you could put the exclude_actions method here and get the same result.
end

Note: Filters ARE NOT applied DURING the execution of a block. Filters are applied to the list of routes that are generated AFTER the block executes.

  • filters are applied to routes contained within a block AFTER the block executes.
  • location of filter statements is irrelevant.
    • top or bottom of the entire file config/routes.rb (applied to the entire file).
    • top or bottom of the block (applied to the entire block).
  • filters can be place directly on a route, resources statement
  • you can include / exclude the following things: actions, controllers, names, verbs

The following example encapsulates and applies filters to a sitemap block, however, contents are included in the default sitemap.

MyApp::Application.routes.draw do

  # included in default sitemap
  root to: 'home#index'
  resources :contact
  resources :faqs

  # using a block to encapsulate, however, contents are included in the default sitemap.
  sitemap do

    exclude_actions :show   # excludes the "show" action from every route witnin the block
    resources :dvd_players
    resources :accessories
    # you could put the exclude_actions method here and get the same result.
  end

end

Have a look at all of the example apps.