爲什麼ERB獨立渲染不能用於實例變量?那是「<%= @test_var%>」行的輸出爲空?爲什麼ERB獨立渲染不能用於實例變量
@test_var = "test variable"
template = Tilt.new('./app/scripts/email.erb')
st = template.render
puts st
和email.erb
<html>
<body>
<h1>This is it!</h1>
<p>
Phone Number: <%= @test_var %>
</p>
</body>
</html>
給
<html>
<body>
<h1>This is it!</h1>
<p>
Phone Number:
</p>
</body>
</html>
爲我工作,你也可以省略函數get_binding並直接傳遞綁定。我想把字符串作爲html,所以我做了'html = rhtml.result(binding)' – portforwardpodcast 2013-06-02 22:57:56