1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib/action_dispatch/middleware/templates/rescues
Tijmen Brommet 08689a2d1f Add text template for source code
When a request is made with AJAX and an error occurs, Rails will render
a text-template for the exception instead of the HTML error page
(#11960).

The `.text.erb` variant of the `_source` template is currently missing,
causing HTML to be rendered in the response. This commit adds the text
template.

To keep the page scannable we only only show the first three source
extracts.

Related to #14745.

Before:

```
~/testing-exceptions  ᐅ curl 'http://localhost:3000/' -H
'X-Requested-With: XMLHttpRequest'
RuntimeError in PostsController#index

    <div class="source " id="frame-source-0">
      <div class="info">
        Extracted source (around line <strong>#3</strong>):
      </div>
      <div class="data">
        <table cellpadding="0" cellspacing="0" class="lines">
          <tr>
```

After:

```
~/testing-exceptions  ᐅ curl 'http://localhost:3000/' -H
'X-Requested-With: XMLHttpRequest'
RuntimeError in PostsController#index

Extracted source (around line #3):

*3     raise
```
2015-11-03 22:13:10 +00:00
..
_request_and_response.html.erb
_request_and_response.text.erb
_source.html.erb Add text template for source code 2015-11-03 22:13:10 +00:00
_source.text.erb Add text template for source code 2015-11-03 22:13:10 +00:00
_trace.html.erb
_trace.text.erb
diagnostics.html.erb
diagnostics.text.erb
layout.erb
missing_template.html.erb
missing_template.text.erb
routing_error.html.erb
routing_error.text.erb
template_error.html.erb
template_error.text.erb
unknown_action.html.erb
unknown_action.text.erb