Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Add :except and :only documentation to the Routing Guide

  • Loading branch information...
commit e5d6b82efbbc21c56316490e9355f0659ba89dea 1 parent c2794b4
@ffmike ffmike authored
Showing with 26 additions and 0 deletions.
  1. +26 −0 railties/doc/guides/source/routing_outside_in.txt
26 railties/doc/guides/source/routing_outside_in.txt
@@ -229,6 +229,8 @@ Although the conventions of RESTful routing are likely to be sufficient for many
* +:path_names+
* +:path_prefix+
* +:name_prefix+
+* +:only+
+* +:except+
You can also add additional routes via the +:member+ and +:collection+ options, which are discussed later in this guide.
@@ -400,6 +402,30 @@ This combination will give you route helpers such as +photographer_photos_path+
NOTE: You can also use +:name_prefix+ with non-RESTful routes.
+==== Using :only and :except
+By default, Rails creates routes for all seven of the default actions (index, show, new, create, edit, update, and destroy) for every RESTful route in your application. You can use the +:only+ and +:except+ options to fine-tune this behavior. The +:only+ option specifies that only certain routes should be generated:
+[source, ruby]
+map.resources :photos, :only => [:index, :show]
+With this declaration, a +GET+ request to +/photos+ would succeed, but a +POST+ request to +/photos+ (which would ordinarily be routed to the create action) will fail.
+The +:except+ option specifies a route or list of routes that should _not_ be generated:
+[source, ruby]
+map.resources :photos, :except => :destroy
+In this case, all of the normal routes except the route for +destroy+ (a +DELETE+ request to +/photos/_id_+) will be generated.
+In addition to an action or a list of actions, you can also supply the special symbols +:all+ or +:none+ to the +:only+ and +:accept+ options.
+TIP: If your application has many RESTful routes, using +:only+ and +:accept+ to generate only the routes that you actually need can cut down on memory use and speed up the routing process.
=== Nested Resources
It's common to have resources that are logically children of other resources. For example, suppose your application includes these models:
Please sign in to comment.
Something went wrong with that request. Please try again.