From 9122143767b419c3be6b8ec86fd9b90ba7c39fe6 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sat, 26 May 2012 16:12:06 +1000 Subject: [routing guide] Add mention of get '/:username' route This is fairly common in Rails applications and is requested a lot of the time on Stack Overflow and #rubyonrails --- guides/source/routing.textile | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'guides/source') diff --git a/guides/source/routing.textile b/guides/source/routing.textile index d77b3bc7cd..0773a96c67 100644 --- a/guides/source/routing.textile +++ b/guides/source/routing.textile @@ -445,6 +445,14 @@ get 'exit' => 'sessions#destroy', :as => :logout This will create +logout_path+ and +logout_url+ as named helpers in your application. Calling +logout_path+ will return +/exit+ +You can also use this to override routing methods defined by resources, like this: + + +get ':username', :to => "users#show", :as => :user + + +This will define a +user_path+ method that will be available in controllers, helpers and views that will go to a route such as +/bob+. Inside the +show+ action of +UsersController+, +params[:username]+ will contain the username for the user. Change +:username+ in the route definition if you do not want your parameter name to be +:username+. + h4. HTTP Verb Constraints In general, you should use the +get+, +post+, +put+ and +delete+ methods to constrain a route to a particular verb. You can use the +match+ method with the +:via+ option to match multiple verbs at once: -- cgit v1.2.3