'How would I use "content_for" in ERB.new?

I'm trying to do something like this:

template = ERB.new <<-EOF
    <% content_for :message do %>
    Message here
    <% end %>
    <%= yield(:message) %>
EOF
template.result(binding)

I tried prepending "include ActionView::Helpers::CaptureHelper" and "@view_flow = ActionView::OutputFlow.new", but got a "LocalJumpError (no block given (yield)" error.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source