Skip to content
SEO Plugin for Ruby-on-Rails to enable more compact routes by declaring a nested resource as the default.
Pull request Compare This branch is 3 commits ahead of jasoncodes:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



This fork (granth/default_routing) cuts a bunch of code. The only thing I
wanted to work with Rails 2.3.11, was using :default => true. I'm not using
the :show option.

This is an SEO Optimization plugin that allows you to specify that one or more nested routes will not have
a path segment added to their url.

When combined with acts_as_url_param (or some other pretty url plugin), this results in nice tight urls without any extra folders in them in the cases where you can safely get away with it.

This plugin adds new new routing options:
* :default - When true, causes the resource to not generate a namespace prefix
* :show - a symbol identifying a nested resource whose index action should *replace* this resources show action.

It's important to note that using a :default nesting results in a url collision that hides the index action of the nested resource. If routing to the index action is more desirable, use the :show option instead.


map.namespace :forum do |forum|
  forum.resources :boards, :default => true, :show => :threads do |boards|
    boards.resources :threads, :show => posts do |threads|
      threads.resources :posts

% rake routes | grep forum | grep -v format

                forum_boards GET    /forum
                             POST   /forum
             new_forum_board GET    /forum/new
            edit_forum_board GET    /forum/:id/edit
                             PUT    /forum/:id
                             DELETE /forum/:id
         forum_board_threads GET    /forum/:board_id             # prevents recognition of forum_board
                             POST   /forum/:board_id
      new_forum_board_thread GET    /forum/:board_id/new
     edit_forum_board_thread GET    /forum/:board_id/:id/edit
                             PUT    /forum/:board_id/:id
                             DELETE /forum/:board_id/:id
    forum_board_thread_posts GET    /forum/:board_id/:thread_id  # prevents recognition of forum_board_thread
                             POST   /forum/:board_id/:thread_id
 new_forum_board_thread_post GET    /forum/:board_id/:thread_id/new
edit_forum_board_thread_post GET    /forum/:board_id/:thread_id/:id/edit
     forum_board_thread_post GET    /forum/:board_id/:thread_id/:id
                             PUT    /forum/:board_id/:thread_id/:id
                             DELETE /forum/:board_id/:thread_id/:id
          forum_board_thread GET    /forum/:board_id/:id
                 forum_board GET    /forum/:id

% script/console
>> app.forum_board_thread_post_path(Board.first, Thread.first, Post.first)
=> "/forum/star-wars/droids/r2d2-rocks-c3po-sucks"

Copyright (c) 2008 Chris Eppstein, released under the MIT license
Something went wrong with that request. Please try again.