From e287b53fe303b46be9ba0127aee686b228092fda Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 31 Mar 2010 14:19:05 +0100 Subject: Update routing documentation to the new way of specifying HTTP method restrictions --- actionpack/lib/action_dispatch/routing.rb | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing.rb b/actionpack/lib/action_dispatch/routing.rb index c6e942555f..2c3623cfa5 100644 --- a/actionpack/lib/action_dispatch/routing.rb +++ b/actionpack/lib/action_dispatch/routing.rb @@ -136,20 +136,32 @@ module ActionDispatch # # == HTTP Methods # - # With conditions you can define restrictions on routes. Currently the only valid condition is :method. + # Using the :via option when specifying a route allows you to restrict it to a specific HTTP method. + # Possible values are :post, :get, :put, :delete and :any. + # If your route needs to respond to more than one method you can use an array, e.g. [ :get, :post ]. + # The default value is :any which means that the route will respond to any of the HTTP methods. # - # * :method - Allows you to specify which HTTP method(s) can access the route. Possible values are - # :post, :get, :put, :delete and :any. Use an array to specify more - # than one method, e.g. [ :get, :post ]. The default value is :any, :any means that any - # method can access the route. + # Examples: # - # Example: + # match 'post/:id' => 'posts#show', :via => :get + # match 'post/:id' => "posts#create_comment', :via => :post + # + # Now, if you POST to /posts/:id, it will route to the create_comment action. A GET on the same + # URL will route to the show action. + # + # === HTTP helper methods # - # get 'post/:id' => 'posts#show' + # An alternative method of specifying which HTTP method a route should respond to is to use the helper + # methods get, post, put and delete. + # + # Examples: + # + # get 'post/:id' => 'posts#show' # post 'post/:id' => "posts#create_comment' # - # Now, if you POST to /posts/:id, it will route to the create_comment action. A GET on the same - # URL will route to the show action. + # This syntax is less verbose and the intention is more apparent to someone else reading your code, + # however if your route needs to respond to more than one HTTP method (or all methods) then using the + # :via option on match is preferable. # # == Reloading routes # -- cgit v1.2.3