diff options
author | Ernie Miller <ernie@erniemiller.org> | 2012-08-23 09:02:37 -0400 |
---|---|---|
committer | Ernie Miller <ernie@erniemiller.org> | 2012-09-03 13:13:16 -0400 |
commit | eb43d3d1d94c67b3bf9c0cf576cdae8380f27260 (patch) | |
tree | 7e275b962d01cda13ce7c34c91efe9a7143173b7 /actionpack/lib/action_dispatch | |
parent | 4037e31d8874250e485ca6a27bd792a3beb13f76 (diff) | |
download | rails-eb43d3d1d94c67b3bf9c0cf576cdae8380f27260.tar.gz rails-eb43d3d1d94c67b3bf9c0cf576cdae8380f27260.tar.bz2 rails-eb43d3d1d94c67b3bf9c0cf576cdae8380f27260.zip |
Fix concerns not executing block in mapper
Also, add documentation for alternate usage.
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 |