rails/web-console — pull request #69 by gsamokovarov (2014-11-23 20:19:13+00:00)
Title: Introduce middleware for request dispatch and console rendering

Having to copy and maintain the Rails templates in sync was trouble. Having `ActionDispatch::DebugExceptions` dispatching requests for Web Console was out of place. Having an after action in the controller, that avoids the render process was bad. It was clear that we need a better solution.

I'm proposing to solve all that with a smartly placed middleware between `ActionDispatch::DebugExceptions` and `ActionDispatch::PublicExceptions`. Now every page can have an attached console, as long as the application passed down the middleware a binding or an exception to extract a binding from.

This makes the `console` view and controller helpers a really thin wrapper that communicates with the middleware. Because we can only attach one binding or one exception, we don't need to handle how to avoid double console rendering.

The error pages are a bit special, because we have a stack of bindings and we can change them. This is done with extra JavaScript working with current `ActionDispatch::DebugExceptions`. The only drawback of this is that it works only with Rails 4.2 templates, but I think this is a good compromise. If this is a requested feature for older Rails installation, we can implement them for them too and it would take only a little bit of JavaScript.

Last and not least, testing the middleware is quite easier, so it can give us more confidence about the console.