From 203e45cd7fcbcb2ca548f778482c3ad0ad82d691 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 10:26:18 +1000 Subject: Add further documentation + examples for the get, post, put and delete methods in ActionDispatch::Routing::Mapper::HttpHelpers --- actionpack/lib/action_dispatch/routing/mapper.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 3c7dcea003..c58562db24 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -323,21 +323,41 @@ module ActionDispatch module HttpHelpers # Define a route that only recognizes HTTP GET. + # For supported arguments, see +match+. + # + # Example: + # + # get 'bacon', :to => 'food#bacon' def get(*args, &block) map_method(:get, *args, &block) end # Define a route that only recognizes HTTP POST. + # For supported arguments, see +match+. + # + # Example: + # + # post 'bacon', :to => 'food#bacon' def post(*args, &block) map_method(:post, *args, &block) end # Define a route that only recognizes HTTP PUT. + # For supported arguments, see +match+. + # + # Example: + # + # put 'bacon', :to => 'food#bacon' def put(*args, &block) map_method(:put, *args, &block) end - # Define a route that only recognizes HTTP DELETE. + # Define a route that only recognizes HTTP PUT. + # For supported arguments, see +match+. + # + # Example: + # + # delete 'broccoli', :to => 'food#broccoli' def delete(*args, &block) map_method(:delete, *args, &block) end -- cgit v1.2.3 From 433e1aca868b148493421b7d3f554c65f50a14ee Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 10:33:06 +1000 Subject: Fix where the documentation says "photos", but the example shows "posts" or "comments" by switching both to simply "posts" --- actionpack/lib/action_dispatch/routing/mapper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index c58562db24..9c5fee9914 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -426,22 +426,22 @@ module ActionDispatch # PUT /admin/photos/1 # DELETE /admin/photos/1 # - # If you want to route /photos (without the prefix /admin) to + # If you want to route /posts (without the prefix /admin) to # Admin::PostsController, you could use # # scope :module => "admin" do - # resources :posts, :comments + # resources :posts # end # # or, for a single case # # resources :posts, :module => "admin" # - # If you want to route /admin/photos to PostsController + # If you want to route /admin/posts to PostsController # (without the Admin:: module prefix), you could use # # scope "/admin" do - # resources :posts, :comments + # resources :posts # end # # or, for a single case -- cgit v1.2.3 From 35c7ca5c3728acffad42a9a77b98f4a098114de5 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 10:34:45 +1000 Subject: Separate comments and examples with "Examples" header. --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 9c5fee9914..d21e1285b3 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -468,6 +468,8 @@ module ActionDispatch # Used to route /photos (without the prefix /admin) # to Admin::PostsController: # + # Examples: + # # scope :module => "admin" do # resources :posts # end -- cgit v1.2.3 From 5040ecbfea931ba20439c7e84f2bdf261edd2732 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 10:38:45 +1000 Subject: Document the :module and :path options for the scope method. --- actionpack/lib/action_dispatch/routing/mapper.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index d21e1285b3..9ff7481c1f 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -467,12 +467,21 @@ module ActionDispatch # Used to route /photos (without the prefix /admin) # to Admin::PostsController: + # === Supported options + # [:module] + # If you want to route /posts (without the prefix /admin) to + # Admin::PostsController, you could use # - # Examples: + # scope :module => "admin" do + # resources :posts + # end + # [:path] + # If you want to prefix the route, you could use # - # scope :module => "admin" do - # resources :posts - # end + # scope :path => "/admin" do + # resources :posts + # end + # This will prefix all of the +posts+ resource's requests with '/admin' def scope(*args) options = args.extract_options! options = options.dup -- cgit v1.2.3 From 5f7f3adccd2ddc1d307e4e5ea4a323562b1cf7ff Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 10:42:33 +1000 Subject: Document the defaults method --- actionpack/lib/action_dispatch/routing/mapper.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 9ff7481c1f..e760eb0196 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -534,6 +534,11 @@ module ActionDispatch scope(:constraints => constraints) { yield } end + # Allows you to set default parameters for a route, such as this: + # defaults :id => 'home' do + # match 'scoped_pages/(:id)', :to => 'pages#show' + # end + # Using this, the +:id+ parameter here will default to 'home'. def defaults(defaults = {}) scope(:defaults => defaults) { yield } end -- cgit v1.2.3 From e5eece41b5ac740f8a137b3228d052273c641099 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 11:49:57 +1000 Subject: Document the controller method for AD's Mapper --- actionpack/lib/action_dispatch/routing/mapper.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index e760eb0196..48afca56d8 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -518,6 +518,12 @@ module ActionDispatch @scope[:blocks] = recover[:block] end + # Scopes routes to a specific controller + # + # Example: + # controller "food" do + # match "bacon", :action => "bacon" + # end def controller(controller, options={}) options[:controller] = controller scope(options) { yield } -- cgit v1.2.3 From 379939e1e00519e819c71a53c28f9032f473aa04 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 12:04:25 +1000 Subject: Begin to document the namespace method for AD's Mapper --- actionpack/lib/action_dispatch/routing/mapper.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 48afca56d8..10b1342f30 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -529,6 +529,21 @@ module ActionDispatch scope(options) { yield } end + # Scopes routes to a specific namespace. For example: + # + # namespace :admin do + # resources :posts + # end + # + # This generates the following routes: + # + # admin_posts GET /admin/posts(.:format) {:action=>"index", :controller=>"admin/posts"} + # admin_posts POST /admin/posts(.:format) {:action=>"create", :controller=>"admin/posts"} + # new_admin_post GET /admin/posts/new(.:format) {:action=>"new", :controller=>"admin/posts"} + # edit_admin_post GET /admin/posts/:id/edit(.:format) {:action=>"edit", :controller=>"admin/posts"} + # admin_post GET /admin/posts/:id(.:format) {:action=>"show", :controller=>"admin/posts"} + # admin_post PUT /admin/posts/:id(.:format) {:action=>"update", :controller=>"admin/posts"} + # admin_post DELETE /admin/posts/:id(.:format) {:action=>"destroy", :controller=>"admin/posts"} def namespace(path, options = {}) path = path.to_s options = { :path => path, :as => path, :module => path, -- cgit v1.2.3 From 0eef4e3bfb3435f2906c70c19ff896393f94abdf Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 12:05:14 +1000 Subject: Document the :path option for namespace --- actionpack/lib/action_dispatch/routing/mapper.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 10b1342f30..f0d3ef80ab 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -544,6 +544,17 @@ module ActionDispatch # admin_post GET /admin/posts/:id(.:format) {:action=>"show", :controller=>"admin/posts"} # admin_post PUT /admin/posts/:id(.:format) {:action=>"update", :controller=>"admin/posts"} # admin_post DELETE /admin/posts/:id(.:format) {:action=>"destroy", :controller=>"admin/posts"} + # === Supported options + # + # The +:path+, +:as+, +:module+, +:shallow_path+ and +:shallow_prefix+ all default to the name of the namespace. + # + # [:path] + # The path prefix for the routes. + # + # namespace :admin, :path => "sekret" do + # resources :posts + # end + # def namespace(path, options = {}) path = path.to_s options = { :path => path, :as => path, :module => path, -- cgit v1.2.3 From 66d1276d7f38ddb002f1dd48e77cea383497f57d Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 12:05:55 +1000 Subject: Document the :module option for namespace --- actionpack/lib/action_dispatch/routing/mapper.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index f0d3ef80ab..34d49591e2 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -555,6 +555,21 @@ module ActionDispatch # resources :posts # end # + # All routes for the above +resources+ will be accessible through +/sekret/posts+, rather than +/admin/posts+ + # + # [:module] + # The namespace for the controllers. + # + # namespace :admin, :module => "sekret" do + # resources :posts + # end + # + # The +PostsController+ here should go in the +Sekret+ namespace and so it should be defined like this: + # + # class Sekret::PostsController < ApplicationController + # # code go here + # end + # def namespace(path, options = {}) path = path.to_s options = { :path => path, :as => path, :module => path, -- cgit v1.2.3 From 6ca042b3e4078b694e827e0f3de51712a0cb4420 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 12:07:29 +1000 Subject: Document the :as option for the namespace method --- actionpack/lib/action_dispatch/routing/mapper.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 34d49591e2..73c2ac3497 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -570,6 +570,14 @@ module ActionDispatch # # code go here # end # + # [:as] + # Changes the name used in routing helpers for this namespace. + # + # namespace :admin, :as => "sekret" do + # resources :posts + # end + # + # Routing helpers such as +admin_posts_path+ will now be +sekret_posts_path+. def namespace(path, options = {}) path = path.to_s options = { :path => path, :as => path, :module => path, -- cgit v1.2.3 From 4a6150a3ebf8e67be4547ac600419d6a68b6ffe1 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 12:09:38 +1000 Subject: Fix indentation on comment for :path option --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 73c2ac3497..939d546f56 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -476,7 +476,7 @@ module ActionDispatch # resources :posts # end # [:path] - # If you want to prefix the route, you could use + # If you want to prefix the route, you could use # # scope :path => "/admin" do # resources :posts -- cgit v1.2.3 From ffe97e338eda6ba2ba946753a8dc4ec64c8968b0 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 12:09:58 +1000 Subject: Space between module option documentation and path documentation --- actionpack/lib/action_dispatch/routing/mapper.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 939d546f56..8244773877 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -475,6 +475,7 @@ module ActionDispatch # scope :module => "admin" do # resources :posts # end + # # [:path] # If you want to prefix the route, you could use # -- cgit v1.2.3 From 7d83673134502b01bcb2fa3be07fdb84c61bb175 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 12:11:39 +1000 Subject: Document the :as option for the scope method --- actionpack/lib/action_dispatch/routing/mapper.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 8244773877..ba0911c635 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -482,7 +482,17 @@ module ActionDispatch # scope :path => "/admin" do # resources :posts # end + # # This will prefix all of the +posts+ resource's requests with '/admin' + # + # [:as] + # Prefixes the routing helpers in this scope with the specified label. + # + # scope :as => "sekret" do + # resources :posts + # end + # + # Helpers such as +posts_path+ will now be +sekret_posts_path+ def scope(*args) options = args.extract_options! options = options.dup -- cgit v1.2.3 From ee646788fc7f8ce0f087dd0afa82fa28cfdffeb9 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 12:17:36 +1000 Subject: Indent code example for :as option --- actionpack/lib/action_dispatch/routing/mapper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index ba0911c635..b39cc5beb6 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -488,9 +488,9 @@ module ActionDispatch # [:as] # Prefixes the routing helpers in this scope with the specified label. # - # scope :as => "sekret" do - # resources :posts - # end + # scope :as => "sekret" do + # resources :posts + # end # # Helpers such as +posts_path+ will now be +sekret_posts_path+ def scope(*args) -- cgit v1.2.3 From e6aed6b6a8fd03584141c7dffd73c12ed32ce3d4 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 12:18:19 +1000 Subject: Indent final comment for :path option --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index b39cc5beb6..3e0802f3fc 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -483,7 +483,7 @@ module ActionDispatch # resources :posts # end # - # This will prefix all of the +posts+ resource's requests with '/admin' + # This will prefix all of the +posts+ resource's requests with '/admin' # # [:as] # Prefixes the routing helpers in this scope with the specified label. -- cgit v1.2.3 From ff3a494e2e3cf52193d42ba7ed8252759de57c01 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 12:21:56 +1000 Subject: Document the :shallow_path option for scope --- actionpack/lib/action_dispatch/routing/mapper.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 3e0802f3fc..a7d85dd3b5 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -493,6 +493,25 @@ module ActionDispatch # end # # Helpers such as +posts_path+ will now be +sekret_posts_path+ + # + # [:shallow_path] + # + # Prefixes nested shallow routes with the specified path. + # + # scope :shallow_path => "sekret" do + # resources :posts do + # resources :comments, :shallow => true + # end + # + # The +comments+ resource here will have the following routes generated for it: + # + # post_comments GET /sekret/posts/:post_id/comments(.:format) + # post_comments POST /sekret/posts/:post_id/comments(.:format) + # new_post_comment GET /sekret/posts/:post_id/comments/new(.:format) + # edit_comment GET /sekret/comments/:id/edit(.:format) + # comment GET /sekret/comments/:id(.:format) + # comment PUT /sekret/comments/:id(.:format) + # comment DELETE /sekret/comments/:id(.:format) def scope(*args) options = args.extract_options! options = options.dup -- cgit v1.2.3 From b591989b5ff472301ba0c99d41268e9682a0651f Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 7 Nov 2010 12:22:39 +1000 Subject: Fix indentation for :as option documentation on the namespace method --- actionpack/lib/action_dispatch/routing/mapper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index a7d85dd3b5..2b3c20f6b9 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -601,11 +601,11 @@ module ActionDispatch # end # # [:as] - # Changes the name used in routing helpers for this namespace. + # Changes the name used in routing helpers for this namespace. # - # namespace :admin, :as => "sekret" do - # resources :posts - # end + # namespace :admin, :as => "sekret" do + # resources :posts + # end # # Routing helpers such as +admin_posts_path+ will now be +sekret_posts_path+. def namespace(path, options = {}) -- cgit v1.2.3 From b235519777b921c0ecf4e20fbeb5f5fe49459775 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sat, 13 Nov 2010 11:15:17 +0800 Subject: Add documentation for the mount method in ActionDispatch's Mapper --- actionpack/lib/action_dispatch/routing/mapper.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 2b3c20f6b9..c3f778a70f 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -262,6 +262,23 @@ module ActionDispatch self end + # Mount a Rack-based application to be used within the application. + # + # mount SomeRackApp, :at => "some_route" + # + # Alternatively: + # + # mount(SomeRackApp => "some_route") + # + # All mounted applications come with routing helpers to access them. + # These are named after the class specified, so for the above example + # the helper is either +some_rack_app_path+ or +some_rack_app_url+. + # To customize this helper's name, use the +:as+ option: + # + # mount(SomeRackApp => "some_route", :as => "exciting") + # + # This will generate the +exciting_path+ and +exciting_url+ helpers + # which can be used to navigate to this mounted app. def mount(app, options = nil) if options path = options.delete(:at) -- cgit v1.2.3 From 95f41fe12e7680459351be633a171abf26beac1a Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sat, 13 Nov 2010 11:16:06 +0800 Subject: See the scope method for documentation for namespace's shallow_path option --- actionpack/lib/action_dispatch/routing/mapper.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index c3f778a70f..cc013ac072 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -625,6 +625,9 @@ module ActionDispatch # end # # Routing helpers such as +admin_posts_path+ will now be +sekret_posts_path+. + # + # [:shallow_path] + # See the +scope+ method. def namespace(path, options = {}) path = path.to_s options = { :path => path, :as => path, :module => path, -- cgit v1.2.3 From fe8446fcced912730b068944b2ce152f18046f77 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sat, 13 Nov 2010 11:16:32 +0800 Subject: Add documentation for :path_names option on resources --- actionpack/lib/action_dispatch/routing/mapper.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index cc013ac072..8b5d7d307b 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -911,6 +911,14 @@ module ActionDispatch # GET /photos/:id/edit # PUT /photos/:id # DELETE /photos/:id + # === Supported options + # [:path_names] + # Allows you to change the paths of the seven default actions. + # Paths not specified are not changed. + # + # resources :posts, :path_names => { :new => "brand_new" } + # + # The above example will now change /posts/new to /posts/brand_new def resources(*resources, &block) options = resources.extract_options! -- cgit v1.2.3 From 74061f55be2ba83f1457369b7e47cab54d26a57f Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 14 Nov 2010 07:32:54 +0800 Subject: Document the constraints method --- actionpack/lib/action_dispatch/routing/mapper.rb | 56 +++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 8b5d7d307b..2eb2af7a11 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -634,7 +634,61 @@ module ActionDispatch :shallow_path => path, :shallow_prefix => path }.merge!(options) scope(options) { yield } end - + + # === Parameter Restriction + # Allows you to constrain the nested routes based on a set of rules. + # For instance, in order to change the routes to allow for a dot character in the +id+ parameter: + # + # constraints(:id => /\d+\.\d+) do + # resources :posts + # end + # + # Now routes such as +/posts/1+ will no longer be valid, but +/posts/1.1+ will be. + # The +id+ parameter must match the constraint passed in for this example. + # + # You may use this to also resrict other parameters: + # + # resources :posts do + # constraints(:post_id => /\d+\.\d+) do + # resources :comments + # end + # + # === Restricting based on IP + # + # Routes can also be constrained to an IP or a certain range of IP addresses: + # + # constraints(:ip => /192.168.\d+.\d+/) do + # resources :posts + # end + # + # Any user connecting from the 192.168.* range will be able to see this resource, + # where as any user connecting outside of this range will be told there is no such route. + # + # === Dynamic request matching + # + # Requests to routes can be constrained based on specific critera: + # + # constraints(lambda { |req| req.env["HTTP_USER_AGENT"] =~ /iPhone/ }) do + # resources :iphones + # end + # + # You are able to move this logic out into a class if it is too complex for routes. + # This class must have a +matches?+ method defined on it which either returns +true+ + # if the user should be given access to that route, or +false+ if the user should not. + # + # class Iphone + # def self.matches(request) + # request.env["HTTP_USER_AGENT"] =~ /iPhone/ + # end + # end + # + # An expected place for this code would be +lib/constraints+. + # + # This class is then used like this: + # + # constraints(Iphone) do + # resources :iphones + # end def constraints(constraints = {}) scope(:constraints => constraints) { yield } end -- cgit v1.2.3