slippyd / default_routing forked from caring/default_routing

SEO Plugin for Ruby-on-Rails to enable more compact routes by declaring a nested resource as the default.

This URL has Read+Write access

Slippy Douglas (author)
Sat Sep 26 01:29:19 -0700 2009
commit  baf836a68d7bf77138b029a872d4eda8c6309c03
tree    27c29f98cc4edb2a6c2fb8a46e2f1afd8384c310
parent  9aa485807130206e0074c78037013d40d622f6bc
name age message
file MIT-LICENSE Thu Jun 12 16:57:11 -0700 2008 initial release [chriseppstein]
file README Mon Jun 16 08:14:21 -0700 2008 This commit allows the index action of the nest... [chriseppstein]
file Rakefile Thu Jun 12 16:57:11 -0700 2008 initial release [chriseppstein]
file init.rb Mon Jun 16 08:14:21 -0700 2008 This commit allows the index action of the nest... [chriseppstein]
directory lib/ Sat Sep 26 01:29:19 -0700 2009 Fixes for Rails 2.3.4 • Was causing a "//" to a... [Slippy Douglas]
directory test/ Thu Jun 12 16:57:11 -0700 2008 initial release [chriseppstein]
README
DefaultRouting
==============

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.

Example
=======

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

% 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