2012-07-20 48 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) 

去而且,你可以使用凱爾的答案從您的模板去再培訓局。