Permalink
Browse files

Improve routes documentation. Closes #7095.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6071 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent dad60e7 commit c5f7997ebc9a49c3b58f007de26569b7e5f1795e @jeremy jeremy committed Jan 28, 2007
Showing with 28 additions and 15 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +26 −15 actionpack/lib/action_controller/routing.rb
@@ -1,5 +1,7 @@
*SVN*
+* Improve routes documentation. #7095 [zackchandler]
+
* mail_to :encode => 'hex' also encodes the mailto: part of the href attribute as well as the linked email when no name is given. #2061 [Jarkko Laine, pfc.pille@gmx.net]
* Resource member routes require :id, eliminating the ambiguous overlap with collection routes. #7229 [dkubb]
@@ -127,7 +127,8 @@ module ActionController
# == Named routes
#
# Routes can be named with the syntax <tt>map.name_of_route options</tt>,
- # allowing for easy reference within your source as +name_of_route_url+.
+ # allowing for easy reference within your source as +name_of_route_url+
+ # for the full URL and +name_of_route_path+ for the URI path.
#
# Example:
# # In routes.rb
@@ -138,29 +139,39 @@ module ActionController
#
# Arguments can be passed as well.
#
- # redirect_to show_item_url(:id => 25)
+ # redirect_to show_item_path(:id => 25)
#
- # When using +with_options+, the name goes after the item passed to the block.
+ # Use <tt>map.root</tt> as a shorthand to name a route for the root path ""
#
- # ActionController::Routing::Routes.draw do |map|
- # map.with_options :controller => 'blog' do |blog|
- # blog.show '', :action => 'list'
- # blog.delete 'delete/:id', :action => 'delete',
- # blog.edit 'edit/:id', :action => 'edit'
- # end
- # map.connect ':controller/:action/:view
- # end
+ # # In routes.rb
+ # map.root :controller => 'blogs'
+ #
+ # # would recognize http://www.example.com/ as
+ # params = { :controller => 'blogs', :action => 'index' }
+ #
+ # # and provide these named routes
+ # root_url # => 'http://www.example.com/'
+ # root_path # => ''
#
- # You would then use the named routes in your views:
+ # Note: when using +with_options+, the route is simply named after the
+ # method you call on the block parameter rather than map.
+ #
+ # # In routes.rb
+ # map.with_options :controller => 'blog' do |blog|
+ # blog.show '', :action => 'list'
+ # blog.delete 'delete/:id', :action => 'delete',
+ # blog.edit 'edit/:id', :action => 'edit'
+ # end
#
- # link_to @article.title, show_url(:id => @article.id)
+ # # provides named routes for show, delete, and edit
+ # link_to @article.title, show_path(:id => @article.id)
#
- # == Pretty URL's
+ # == Pretty URLs
#
# Routes can generate pretty URLs. For example:
#
# map.connect 'articles/:year/:month/:day',
- # :controller => 'articles',
+ # :controller => 'articles',
# :action => 'find_by_date',
# :year => /\d{4}/,
# :month => /\d{1,2}/,

0 comments on commit c5f7997

Please sign in to comment.