aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-08-12 14:25:09 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-08-12 14:30:53 -0700
commit58117fadae1ccc1d84672cbecdc965727245e0fe (patch)
treee97541d225ca2d62273d30716989dcf697d3b434 /actionpack
parentb46c67fb472fc78c7b2aa225cba041ffe4d5c061 (diff)
downloadrails-58117fadae1ccc1d84672cbecdc965727245e0fe.tar.gz
rails-58117fadae1ccc1d84672cbecdc965727245e0fe.tar.bz2
rails-58117fadae1ccc1d84672cbecdc965727245e0fe.zip
pull via checking up to via extraction
now we don't need to construct a Mapping object just to get an ArgumentError if there is no `via` parameter provided.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb26
1 files changed, 15 insertions, 11 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index b79f077578..bf35a2b960 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -80,6 +80,18 @@ module ActionDispatch
new set, path, defaults, as, controller, default_action, scope[:module], to, formatted, scope_constraints, scope[:blocks] || [], via, options
end
+ def self.check_via(via)
+ if via.empty?
+ msg = "You should not use the `match` method in your router without specifying an HTTP method.\n" \
+ "If you want to expose your action to both GET and POST, add `via: [:get, :post]` option.\n" \
+ "If you want to expose your action to GET, use `get` in the router:\n" \
+ " Instead of: match \"controller#action\"\n" \
+ " Do: get \"controller#action\""
+ raise ArgumentError, msg
+ end
+ via
+ end
+
def initialize(set, path, defaults, as, controller, default_action, modyoule, to, formatted, scope_constraints, blocks, via, options)
@defaults = defaults
@set = set
@@ -227,16 +239,6 @@ module ActionDispatch
def add_request_method(via, conditions)
return if via == [:all]
-
- if via.empty?
- msg = "You should not use the `match` method in your router without specifying an HTTP method.\n" \
- "If you want to expose your action to both GET and POST, add `via: [:get, :post]` option.\n" \
- "If you want to expose your action to GET, use `get` in the router:\n" \
- " Instead of: match \"controller#action\"\n" \
- " Do: get \"controller#action\""
- raise ArgumentError, msg
- end
-
conditions[:request_method] = via.map { |m| m.to_s.dasherize.upcase }
end
@@ -1540,7 +1542,9 @@ module ActionDispatch
controller = options.delete(:controller) || @scope[:controller]
option_path = options.delete :path
to = options.delete :to
- via = Array(options.delete(:via) { (@scope[:options] || {})[:via] })
+ via = Mapping.check_via Array(options.delete(:via) {
+ (@scope[:options] || {})[:via]
+ })
path_types = paths.group_by(&:class)
path_types.fetch(String, []).each do |_path|