aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http
diff options
context:
space:
mode:
authorJorge Bejar <jorge@wyeworks.com>2015-07-06 14:12:00 -0300
committerJorge Bejar <jorge@wyeworks.com>2015-12-08 21:23:47 -0300
commitb79bfaadaf5b5c6d3e458c24184a0e846bd8cf55 (patch)
tree4ad6e30dec0ffd6380bf85226e8555e2acab5fd3 /actionpack/lib/action_dispatch/http
parenta61e4ae58d65d43a97e90bdb02b6c407791e3c53 (diff)
downloadrails-b79bfaadaf5b5c6d3e458c24184a0e846bd8cf55.tar.gz
rails-b79bfaadaf5b5c6d3e458c24184a0e846bd8cf55.tar.bz2
rails-b79bfaadaf5b5c6d3e458c24184a0e846bd8cf55.zip
Use URL path extension as format in bad params exception handling
Diffstat (limited to 'actionpack/lib/action_dispatch/http')
-rw-r--r--actionpack/lib/action_dispatch/http/parameters.rb19
1 files changed, 17 insertions, 2 deletions
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