diff options
author | Ryan Bigg <radarlistener@gmail.com> | 2012-05-26 16:12:06 +1000 |
---|---|---|
committer | Ryan Bigg <radarlistener@gmail.com> | 2012-05-26 16:12:37 +1000 |
commit | 9122143767b419c3be6b8ec86fd9b90ba7c39fe6 (patch) | |
tree | ac5bfee553fe836beefcc3ca40961e7ff387b31b | |
parent | 7a323e2ed15e06f468d783340c4680c5ad235e87 (diff) | |
download | rails-9122143767b419c3be6b8ec86fd9b90ba7c39fe6.tar.gz rails-9122143767b419c3be6b8ec86fd9b90ba7c39fe6.tar.bz2 rails-9122143767b419c3be6b8ec86fd9b90ba7c39fe6.zip |
[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
-rw-r--r-- | guides/source/routing.textile | 8 |
1 files changed, 8 insertions, 0 deletions
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: + +<ruby> +get ':username', :to => "users#show", :as => :user +</ruby> + +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: |