diff options
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 21 |
1 files changed, 19 insertions, 2 deletions
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 |