David Rz Ayala
David Rz Ayala

Reputation: 2235

How can I convert erb to html?

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

Answers (2)

Jesse Wolgamott
Jesse Wolgamott

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

Kyle
Kyle

Reputation: 22258

Try this...

ERB.new(@template.source).result

ERB#new

Upvotes: 6

Related Questions