提交 37b4276d 编写于 作者: A Andrew White

Fix shorthand routes where controller and action are in the scope

Merge `:action` from routing scope and assign endpoint if both `:controller`
and `:action` are present. The endpoint assignment only occurs if there is
no `:to` present in the options hash so should only affect routes using the
shorthand syntax (i.e. endpoint is inferred from the the path).

Fixes #9856
上级 55d9176b
* Merge `:action` from routing scope and assign endpoint if both `:controller`
and `:action` are present. The endpoint assignment only occurs if there is
no `:to` present in the options hash so should only affect routes using the
shorthand syntax (i.e. endpoint is inferred from the the path).
Fixes #9856
*Yves Senn*, *Andrew White*
* ActionView extracted from ActionPack
*Piotr Sarnacki*, *Łukasz Strzałkowski*
......
......@@ -11,8 +11,8 @@ module Routing
class Mapper
URL_OPTIONS = [:protocol, :subdomain, :domain, :host, :port]
SCOPE_OPTIONS = [:path, :shallow_path, :as, :shallow_prefix, :module,
:controller, :path_names, :constraints, :defaults,
:shallow, :blocks, :options]
:controller, :action, :path_names, :constraints,
:shallow, :blocks, :defaults, :options]
class Constraints #:nodoc:
def self.new(app, constraints, request = Rack::Request)
......@@ -874,6 +874,10 @@ def merge_controller_scope(parent, child) #:nodoc:
child
end
def merge_action_scope(parent, child) #:nodoc:
child
end
def merge_path_names_scope(parent, child) #:nodoc:
merge_options_scope(parent, child)
end
......@@ -1383,6 +1387,10 @@ def match(path, *rest)
raise ArgumentError, "Unknown scope #{on.inspect} given to :on"
end
if @scope[:controller] && @scope[:action]
options[:to] ||= "#{@scope[:controller]}##{@scope[:action]}"
end
paths.each do |_path|
route_options = options.dup
route_options[:path] ||= _path if _path.is_a?(String)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册