Reputation: 2235
Imagine in rails I have @template
that is an instance of ActionTemplate::View
.
Question is: How can I convert @template
whose @template.source is <%= "hello from erb" %>
to hello from erb
?? thanks
Upvotes: 3
Views: 6200
Reputation: 40277
Well... messing around with ActionView::Template.new
outside of Rails is not really recommended. You need a ton of stuff setup beforehand (init and render)
If you do want to just use ERB, then go with this example
require 'erb'
x = 42
template = ERB.new <<-EOF
The value of x is: <%= x %>
EOF
puts template.result(binding)
And, you can use Kyle's answer to go from your template to ERB.
Upvotes: 4