我有一个帮助,需要一个块:
def container(&block)
render(:partial => 'layouts/container', :locals => {:content => capture(&block)})
end
当我尝试在ERB中的<%= ... %>
标记内使用它时:
<%= container do %>
Test
<% end %>
我得到compile error
:
compile error
test2.html.erb:1: syntax error, unexpected ')'
old_output_buffer = output_buffer;;@output_buffer = ''; __in_erb_template=true ; @output_buffer.concat(( container do ).to_s); @output_buffer.concat "\r\n"
^
test2.html.erb:4: syntax error, unexpected kENSURE, expecting ')'
test2.html.erb:6: syntax error, unexpected kEND, expecting ')'
但是,如果我捕获帮助器的输出然后输出它:
<% output = container do %>
Test
<% end %>
<%= output %>
它运作正常,但很难看。
有什么方法可以做我想做的事吗? (注意:通常我使用HAML,但我正在努力让我的助手为正在ERB中工作的团队中的其他人工作;切换到HAML不是解决方案。)