From b79bfaadaf5b5c6d3e458c24184a0e846bd8cf55 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Mon, 6 Jul 2015 14:12:00 -0300 Subject: Use URL path extension as format in bad params exception handling --- actionpack/lib/action_dispatch/http/parameters.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_dispatch/http') diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb index c9df787351..5c20bc53c2 100644 --- a/actionpack/lib/action_dispatch/http/parameters.rb +++ b/actionpack/lib/action_dispatch/http/parameters.rb @@ -41,9 +41,9 @@ module ActionDispatch # Returns a hash with the \parameters used to form the \path of the request. # Returned hash keys are strings: # - # {'action' => 'my_action', 'controller' => 'my_controller'} + # {'action' => 'my_action', 'controller' => 'my_controller', format => 'html'} def path_parameters - get_header(PARAMETERS_KEY) || {} + get_header(PARAMETERS_KEY) || default_path_parameters end private @@ -66,6 +66,21 @@ module ActionDispatch def params_parsers ActionDispatch::Request.parameter_parsers end + + def default_path_parameters + if format = format_from_path_extension + { 'format' => format } + else + {} + end + end + + def format_from_path_extension + path = @env['action_dispatch.original_path'] + if match = path.match(/\.(\w+)$/) + match.captures.first + end + end end end end -- cgit v1.2.3