Read more

Get compiled code of a view template in Rails 4.2

Tobias Kraze
March 18, 2016Software engineer at makandra GmbH

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))
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

The output will be something like

@output_buffer = output_buffer || ActionView::OutputBuffer.new;@output_buffer.safe_append='My template
'.freeze;@output_buffer.to_s
Posted by Tobias Kraze to makandra dev (2016-03-18 15:19)