From 0bd7b07dff253e0fc2d01644371680bafa0df372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 10 Aug 2012 00:06:16 -0300 Subject: Add CHANGELOG entry and documentation for Routing Concerns --- guides/source/routing.textile | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'guides/source') 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. + + +concern :commentable do + resources :comments +end + +concern :image_attachable do + resources :images, only: :index +end + + +These concerns can be used in resources to avoid code duplication and share behavior across routes. + + +resources :messages, concerns: :commentable + +resources :posts, concerns: [:commentable, :image_attachable] + + +Also you can use them in any place that you want inside the routes, for example in a scope or namespace call: + + +namespace :posts do + concerns :commentable +end + + 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: -- cgit v1.2.3