From 08689a2d1f0165f353f62ef4626e87fe841ec735 Mon Sep 17 00:00:00 2001 From: Tijmen Brommet Date: Tue, 3 Nov 2015 21:26:59 +0000 Subject: Add text template for source code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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
Extracted source (around line #3):
``` After: ``` ~/testing-exceptions ᐅ curl 'http://localhost:3000/' -H 'X-Requested-With: XMLHttpRequest' RuntimeError in PostsController#index Extracted source (around line #3): *3 raise ``` --- .../middleware/templates/rescues/_source.html.erb | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 actionpack/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (limited to 'actionpack/lib/action_dispatch/middleware/templates/rescues/_source.html.erb') diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.html.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.html.erb new file mode 100644 index 0000000000..e7b913bbe4 --- /dev/null +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.html.erb @@ -0,0 +1,27 @@ +<% @source_extracts.each_with_index do |source_extract, index| %> + <% if source_extract[:code] %> +
" id="frame-source-<%=index%>"> +
+ Extracted source (around line #<%= source_extract[:line_number] %>): +
+
+
+ + + + +
+
+                <% source_extract[:code].each_key do |line_number| %>
+<%= line_number -%>
+                <% end %>
+              
+
+
+<% source_extract[:code].each do |line, source| -%>
"><%= source -%>
<% end -%> +
+
+
+
+ <% end %> +<% end %> -- cgit v1.2.3