mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Allow scope to take :path and :controller options
This commit is contained in:
@@ -216,6 +216,27 @@ module ActionDispatch
|
||||
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 @@ module ActionDispatch
|
||||
|
||||
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
|
||||
|
||||
@@ -94,7 +94,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user