Ruby 产生一个 ERB 模板优于另一个的方法

Ruby method that yields one ERB template over another

我需要知道如何编写一个方法来获取下面的页面 ERB

<h1>Hello World</h1>

并在下面的布局 ERB 模板中产生收益

<html>
<head>
  <title>Layout</title>
</head>
<body>
  <%= yield %>
</body>
</html>

已编辑:

我实际上是在寻找一个简单的 method/function,devanand 向我推荐了一个 link。以下是我的工作,因为我对如何为此编写方法一无所知。

page = "<h1>Hello World</h1>"

layout = "<html>
<head>
  <title>Layout</title>
</head>
<body>
  <%= yield %>
</body>
</html>"

def render_layout(layout)
  ERB.new(layout).result(binding)
end

def render_view_with_layout(view, layout)
  render_layout(layout) do 
    ERB.new(view).result
  end  
end

希望我能回答您的问题。 以下 link 应该可以回答您的问题

How can I use views and layouts with Ruby and ERB (not Rails)?