aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-13 21:44:13 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-13 21:44:13 -0300
commit2d9dbf416b14610cc21fc10e68700c3a7ffc32a3 (patch)
treea758df96d03e3756d22b7d588d9fabf976eb31d4 /guides/source
parentfa736e69a197522ae3af3d3e6394cdc1eb1da228 (diff)
parent0bd7b07dff253e0fc2d01644371680bafa0df372 (diff)
downloadrails-2d9dbf416b14610cc21fc10e68700c3a7ffc32a3.tar.gz
rails-2d9dbf416b14610cc21fc10e68700c3a7ffc32a3.tar.bz2
rails-2d9dbf416b14610cc21fc10e68700c3a7ffc32a3.zip
Merge branch 'concerns'
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/routing.textile30
1 files changed, 30 insertions, 0 deletions
diff --git a/guides/source/routing.textile b/guides/source/routing.textile
index cffbf9bec4..bed7d03e06 100644
--- a/guides/source/routing.textile
+++ b/guides/source/routing.textile
@@ -273,6 +273,36 @@ The corresponding route helper would be +publisher_magazine_photo_url+, requirin
TIP: _Resources should never be nested more than 1 level deep._
+h4. Routing concerns
+
+Routing Concerns allows you to declare common routes that can be reused inside others resources and routes.
+
+<ruby>
+concern :commentable do
+ resources :comments
+end
+
+concern :image_attachable do
+ resources :images, only: :index
+end
+</ruby>
+
+These concerns can be used in resources to avoid code duplication and share behavior across routes.
+
+<ruby>
+resources :messages, concerns: :commentable
+
+resources :posts, concerns: [:commentable, :image_attachable]
+</ruby>
+
+Also you can use them in any place that you want inside the routes, for example in a scope or namespace call:
+
+<ruby>
+namespace :posts do
+ concerns :commentable
+end
+</ruby>
+
h4. Creating Paths and URLs From Objects
In addition to using the routing helpers, Rails can also create paths and URLs from an array of parameters. For example, suppose you have this set of routes: