【发布时间】:2014-11-02 02:27:16
【问题描述】:
如何在 Ruby 和 ERB(不是 Rails)中使用视图和布局?
今天我正在使用此代码来呈现我的视图:
def render(template_path, context = self)
template = File.read(template_path)
ERB.new(template).result(context.get_binding)
end
这很好用,但是我怎样才能实现相同的功能,但要在布局中呈现模板呢?我想调用 render_with_layout(template_path, context = self),这样它就会有一个默认布局。
【问题讨论】:
-
render_with_layout是 Rails 特有的东西。你准备好重新实现它了吗?