Get compiled code of a view template in Rails 4.2

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
Tobias Kraze About 8 years ago