Skip to content

Commit

Permalink
always pull out a via variable and simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jun 3, 2014
1 parent 16e2107 commit 6a3cbac
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -213,19 +213,22 @@ def normalize_conditions!(path_params, path, ast)
end
@conditions[:required_defaults] = required_defaults

via_all = options.delete(:via) if options[:via] == :all

if !via_all && options[:via].blank?
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 = options[:via]

if via == :all
options.delete(:via)
else
via = Array(via).compact
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

if via = options[:via]
@conditions[:request_method] = Array(via).map { |m| m.to_s.dasherize.upcase }
@conditions[:request_method] = via.map { |m| m.to_s.dasherize.upcase }
end
end

Expand Down

0 comments on commit 6a3cbac

Please sign in to comment.