aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/routing.textile
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-10 00:06:16 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-13 21:43:18 -0300
commit0bd7b07dff253e0fc2d01644371680bafa0df372 (patch)
treea758df96d03e3756d22b7d588d9fabf976eb31d4 /guides/source/routing.textile
parent546497d027f9e4e55e99dbf7b499bb091d6b5d24 (diff)
downloadrails-0bd7b07dff253e0fc2d01644371680bafa0df372.tar.gz
rails-0bd7b07dff253e0fc2d01644371680bafa0df372.tar.bz2
rails-0bd7b07dff253e0fc2d01644371680bafa0df372.zip
Add CHANGELOG entry and documentation for Routing Concerns
Diffstat (limited to 'guides/source/routing.textile')
-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: