Permalink
Browse files

Allow scope to take :path and :controller options

  • Loading branch information...
1 parent 6637543 commit 40ad54e3811913c2bc60c7ee292fa48862f12001 @josh josh committed Dec 8, 2009
Showing with 22 additions and 14 deletions.
  1. +21 −13 actionpack/lib/action_dispatch/routing/mapper.rb
  2. +1 −1 actionpack/test/dispatch/routing_test.rb
View
34 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -216,6 +216,27 @@ def self.extended(object)
def scope(*args)
options = args.extract_options!
+ case args.first
+ when String
+ options[:path] = args.first
+ when Symbol
+ options[:controller] = args.first
+ end
+
+ if path = options.delete(:path)
+ path_set = true
+ path, @scope[:path] = @scope[:path], "#{@scope[:path]}#{Rack::Mount::Utils.normalize_path(path)}"
+ else
+ path_set = false
+ end
+
+ if controller = options.delete(:controller)
+ controller_set = true
+ controller, @scope[:controller] = @scope[:controller], controller
+ else
+ controller_set = false
+ end
+
constraints = options.delete(:constraints) || {}
unless constraints.is_a?(Hash)
block, constraints = constraints, {}
@@ -225,19 +246,6 @@ def scope(*args)
options, @scope[:options] = @scope[:options], (@scope[:options] || {}).merge(options)
- path_set = controller_set = false
-
- case args.first
- when String
- path_set = true
- path = args.first
- path, @scope[:path] = @scope[:path], "#{@scope[:path]}#{Rack::Mount::Utils.normalize_path(path)}"
- when Symbol
- controller_set = true
- controller = args.first
- controller, @scope[:controller] = @scope[:controller], controller
- end
-
yield
self
View
2 actionpack/test/dispatch/routing_test.rb
@@ -94,7 +94,7 @@ def self.matches?(request)
controller :articles do
scope 'articles' do
- scope ':title', :title => /[a-z]+/, :as => :with_title do
+ scope :path => ':title', :title => /[a-z]+/, :as => :with_title do
match ':id', :to => :with_id
end
end

0 comments on commit 40ad54e

Please sign in to comment.