如何在 Ruby 和 ERB(不是 Rails)中使用视图和布局?
今天我使用这个代码来呈现我的观点:
def render(template_path, context = self)
template = File.read(template_path)
ERB.new(template).result(context.get_binding)
end
Run Code Online (Sandbox Code Playgroud)
这工作得很好,但我如何实现相同的功能,但要在布局内呈现模板?我想调用 render_with_layout(template_path, context = self),这样它就有一个默认布局。