我想将我的邮件模板以 erb 格式存储在我的数据库中。 在我的模板中,我需要访问与 Rails 中基于常规文件的模板基本相同的帮助程序和实例变量。这就是我的邮件程序中的内容:
...
template = ERB.new(erb_from_db)
result = template.result(binding)
...
rails 是否传递实际的 Controller 绑定(bind),或者是否存在更好的绑定(bind),我应该传递给模板而不是 Controller 绑定(bind)?
我也读过有关 render_to_string
的内容,但看起来它不适合我,但我不确定。
或者您还有其他建议吗?
最佳答案
这有效
<div class="ibox-content">
<% erb = ERB.new(@article.body.gsub!("<","<").gsub!(">",">")) rescue ERB.new(@article.body)%>
<%= render :inline => erb.result(binding), :layout => false%>
</div>
关于database - 从数据库渲染 erb 的最佳方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19192297/