Get compiled code of a view template in Rails 4.2

Posted . Visible to the public.

If you want to inspect the compiled code of your erb (or haml) templates, you can run the following code in your view or your controller:

template = lookup_context.find_template(action_name, lookup_context.prefixes)
template.handler.call(template.refresh(self))

The output will be something like

@output_buffer = output_buffer || ActionView::OutputBuffer.new;@output_buffer.safe_append='My template
'.freeze;@output_buffer.to_s
Profile picture of Tobias Kraze
Tobias Kraze
Last edit
Tobias Kraze
License
Source code in this card is licensed under the MIT License.
Posted by Tobias Kraze to makandra dev (2016-03-18 14:19)