aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorMike Gunderloy <MikeG1@larkfarm.com>2008-11-12 08:27:47 -0600
committerMike Gunderloy <MikeG1@larkfarm.com>2008-11-12 08:27:47 -0600
commite5d6b82efbbc21c56316490e9355f0659ba89dea (patch)
tree5b14caec48892bfe1e36dc07dcc0486dfd78b4e6 /railties
parentc2794b49575d919bdbce720a09f9441011813576 (diff)
downloadrails-e5d6b82efbbc21c56316490e9355f0659ba89dea.tar.gz
rails-e5d6b82efbbc21c56316490e9355f0659ba89dea.tar.bz2
rails-e5d6b82efbbc21c56316490e9355f0659ba89dea.zip
Add :except and :only documentation to the Routing Guide
Diffstat (limited to 'railties')
-rw-r--r--railties/doc/guides/source/routing_outside_in.txt26
1 files changed, 26 insertions, 0 deletions
diff --git a/railties/doc/guides/source/routing_outside_in.txt b/railties/doc/guides/source/routing_outside_in.txt
index a9ebb7bc36..1870ceff3e 100644
--- a/railties/doc/guides/source/routing_outside_in.txt
+++ b/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: