From eb43d3d1d94c67b3bf9c0cf576cdae8380f27260 Mon Sep 17 00:00:00 2001 From: Ernie Miller Date: Thu, 23 Aug 2012 09:02:37 -0400 Subject: Fix concerns not executing block in mapper Also, add documentation for alternate usage. --- actionpack/lib/action_dispatch/routing/mapper.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index b1abbbe505..8573f4d80b 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1606,15 +1606,32 @@ module ActionDispatch # concerns :commentable # end module Concerns - # Define a routing concern using a name. + # Define a routing concern using a name. If a second parameter is + # supplied, it should respond to call, which will receive the mapper + # as a parameter, allowing for customized behavior based on the current + # scope. # # concern :commentable do # resources :comments # end # + # # - or - + # + # class Commentable + # def self.call(mapper) + # if mapper.current_scope[:controller] == 'videos' + # mapper.resources :video_comments, as: :comments + # else + # mapper.resources :comments + # end + # end + # end + # + # concern :commentable, Commentable + # # Any routing helpers can be used inside a concern. def concern(name, callable = nil, &block) - @concerns[name] = callable || block + @concerns[name] = callable || lambda { |m| m.instance_eval(&block) } end # Use the named concerns -- cgit v1.2.3