aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2015-12-09 15:26:46 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2015-12-09 15:26:46 -0300
commitb11bca98bf5431ce9522c6b5707f51cd8d7f401c (patch)
treef665325e17cb88cdc8b8ae3ef8750806a02ed0c3 /actionpack/lib/action_dispatch/http
parentb05801754f6423a1d90954ef3f6e2f5dc55c6320 (diff)
parentcdb7a8477ff19f8ed6f549cedc901bd5934a61e8 (diff)
downloadrails-b11bca98bf5431ce9522c6b5707f51cd8d7f401c.tar.gz
rails-b11bca98bf5431ce9522c6b5707f51cd8d7f401c.tar.bz2
rails-b11bca98bf5431ce9522c6b5707f51cd8d7f401c.zip
Merge pull request #20831 from jmbejar/rails-api-json-error-response
Rails API: Ability to return error responses in json format also in development
Diffstat (limited to 'actionpack/lib/action_dispatch/http')
-rw-r--r--actionpack/lib/action_dispatch/http/mime_negotiation.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb
index 7acf91902d..0152c17ed4 100644
--- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb
+++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb
@@ -67,6 +67,8 @@ module ActionDispatch
v = if params_readable
Array(Mime[parameters[:format]])
+ elsif format = format_from_path_extension
+ Array(Mime[format])
elsif use_accept_header && valid_accept_header
accepts
elsif xhr?
@@ -160,6 +162,13 @@ module ActionDispatch
def use_accept_header
!self.class.ignore_accept_header
end
+
+ def format_from_path_extension
+ path = @env['action_dispatch.original_path'] || @env['PATH_INFO']
+ if match = path && path.match(/\.(\w+)\z/)
+ match.captures.first
+ end
+ end
end
end
end