1

How could I manually render a rails error page from an exception ?

I mean the real rails error page, not a custom one:

enter image description here

I have an exception, and I need the html of this rails template from it.

EDIT :

As @Зелёный suggested, I can use templates from here, now the question is how can I render this ?

render 'rescues/diagnostics' #=> ActionView::MissingTemplate

jvenezia
  • 890
  • 7
  • 10

1 Answers1

2

You cant find all templates in path_to_your_gems_folder/gems/actionpack-x.x.x/lib/action_dispatch/middleware/.

Look into sources of actionpack I suggest you to make a custom template and use styles and html from the rails sources.

So answer it is you cant just render a rails error page, because it is complex erb views with own variables and layouts.

Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103
  • Thanks, this actually helps me a lot. Do you know how can I render It ? render 'rescues/diagnostics' does not work. I think it is possible to render it, I have the data (@exception and @request). – jvenezia Apr 15 '15 at 14:03
  • @jvenezia look at [`Rescuable`](http://api.rubyonrails.org/classes/ActiveSupport/Rescuable/ClassMethods.html) it is rails api for rescue errors. of look at this [`answer`](http://stackoverflow.com/questions/9638751/how-to-render-500-page-in-rescue-from). – Roman Kiselenko Apr 15 '15 at 14:09
  • I am using rescue_from to handle exceptions. But my goal is to show html of an exception thrown in js format, so I can see it directly in the browser, without having to go to the console. So my idea was to do something like this in response to a format.js exception : $('body').html("<%= render 'the_rails_template_for_exceptions' %>"); – jvenezia Apr 15 '15 at 14:12
  • `render :template => "shared/500.js"` where `shared/500.js` it is js code `$('body').html("<%= render 'the_rails_template_for_exceptions', exception: @exception %>")` something like this. Doesn't test it but i pretty sure it is possible just need some research and test. Have not time to it for now. – Roman Kiselenko Apr 15 '15 at 14:14
  • I will, thank you for your help ! I will upvote and complete when I'm done :) – jvenezia Apr 15 '15 at 14:19