Skip to content

Commit ae3055b

Browse files
authored
Merge pull request #311 from crobbo/fix-rails-8.2-debug-exceptions
Fix Rails 8.2 compatibility for debug_exceptions patch
2 parents 5d964a6 + acc0e1f commit ae3055b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/patches/debug_exceptions.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@
55
# The original source needs to be patched, so that Inertia requests are
66
# NOT responded with plain text, but with HTML.
77
#
8-
# Original source (unchanged since Rails 5.1):
9-
# https://github.com/rails/rails/blob/5-1-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
8+
# Original source:
109
# https://github.com/rails/rails/blob/8-0-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
10+
# https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
1111
#
1212

1313
module InertiaRails
1414
module InertiaDebugExceptions
15-
def render_for_browser_request(request, wrapper)
15+
# Rails 8.2+ passes content_type as third argument
16+
def render_for_browser_request(request, wrapper, content_type = nil)
1617
template = create_template(request, wrapper)
1718
file = "rescues/#{wrapper.rescue_template}"
1819

19-
if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only
20+
if content_type == Mime[:md]
21+
body = template.render(template: file, layout: false, formats: [:text])
22+
format = 'text/markdown'
23+
elsif request.xhr? && !request.headers['X-Inertia']
2024
body = template.render(template: file, layout: false, formats: [:text])
2125
format = 'text/plain'
2226
else

0 commit comments

Comments
 (0)