Posted 7 months ago. Visible to the public. Repeats.

Unpoly: Automatically show the full better_errors page when Rails raises an error

When an AJAX request raises an exception on the server, Rails will show a minimal error page with only basic information. Because all Unpoly updates work using AJAX requests, you won't get the more detailled better_errors page with the interactive REPL.

Below is an event listener that automatically repeats the request as a full-page load if your development error shows an error page. This means you get a second request, but the error page will show with full CSS and JavaScript:

// Only do this in development. This requires a `[data-environment="development"]` attribute on your `<body>` element. // See if (document.body.dataset.environment == 'development') { // Returns true when your development server shows an error page. function isDevelopmentError(response) { return response.isError() && /Full backtrace|Better errors/.test(response.text) } // When the development server shows an error page, repeat the request as a full page load. up.on('up:proxy:loaded', function(event) { if (isDevelopmentError(event.response)) { event.request.navigate() } }) }

The code assumes you are using Ruby on Rails with better_errors, which is the default error view that modern Rails versions employ. If you are using another method to show development errors you need to update the isDevelopmentError() function so it returns true when your particular development server shows an error.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Henning Koch
Last edit:
7 months ago
by Besprechungs-PC
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more