aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2013-06-25 06:04:26 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2013-06-25 06:04:26 +0100
commit37b4276dbf22382788f66bd5361f0736aadb0425 (patch)
tree560f7cd9255afa0385c2786e1e1b9d6704af4a6f /actionpack
parent55d9176b4a07c5b4f91146d1d38926bee5088b5a (diff)
downloadrails-37b4276dbf22382788f66bd5361f0736aadb0425.tar.gz
rails-37b4276dbf22382788f66bd5361f0736aadb0425.tar.bz2
rails-37b4276dbf22382788f66bd5361f0736aadb0425.zip
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
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md9
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb12
2 files changed, 19 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 0536d39e42..59d9c89c8e 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,12 @@
+* 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*
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 3c58a2cfc3..288ce3e867 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -11,8 +11,8 @@ module ActionDispatch
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 @@ module ActionDispatch
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 @@ module ActionDispatch
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)