brentd / xray-rails

☠️ A development tool that reveals your UI's bones
MIT License
1.22k stars 79 forks source link

Add Rails 5 compatibility #70

Closed mattbrictson closed 8 years ago

mattbrictson commented 8 years ago

Two changes were necessary to add support for Rails 5.

  1. Rails 5 has a new rendering system that allows code such as xray's to render a view to a String from outside of a controller. This works using the new ApplicationController.render method. The old technique no longer works. To work without breaking compatibility with older Rails versions, we check to see if the new render method exists and use it if available; otherwise fall back to the previous technique.
  2. Rails 5 uses streaming responses that are implicitly "committed" once the body of the response is read. Since xray must read the response in order to modify it (i.e. inject its JS), this causes the response to be considered committed, preventing changes to its headers. Hence we can no longer change the "Content-Length" header after modifying the body. We can still do so for older versions of Rails, but now we skip it if the response has the Rails 5 committed? flag.

These changes were tested with Rails 5.0.0.rc1.

Fixes #63.

mattbrictson commented 8 years ago

Perhaps this is bad form, but I'm going to merge my own PR. 😅