2012-07-20 64 views
2

想象一下,我有@template这是一个ActionTemplate::View的实例。如何将erb转换为html?

问题是:我如何将@template转换为@ template.source为<%= "hello from erb" %>hello from erb?感谢

+0

也许'render @ template',从未见过任何实际意义上使用的模板实例 – DVG 2012-07-20 03:31:12

回答

3

尝试......

ERB.new(@template.source).result 

ERB#new

2

嗯...有ActionView::Template.new以外的Rails的插科打诨并不推荐使用。你需要一吨的东西建立事前(initrender)的

如果你想只使用ERB,然后用这个例子

require 'erb' 

x = 42 
template = ERB.new <<-EOF 
    The value of x is: <%= x %> 
EOF 
puts template.result(binding) 

去而且,你可以使用凯尔的答案从您的模板去再培训局。