<%=,在导轨4中有一个块

问题描述:

我正在尝试在帮助程序中使用块,

I'm trying to use a block in a helper,

但这给了我这个错误:

SyntaxError - syntax error, unexpected ')'
...rbout.concat(( green_title do ).to_s); _erbout.concat "\n   ...
...                               ^
(erb):4254: syntax error, unexpected end-of-input, expecting ')'
; _erbout.force_encoding(__ENCODING__)
                                      ^:
  (erb):1649:in `'

这是我的称呼方式:

  <%= green_title do %>
    text
  <% end %>

这是我的助手:

  def green_title(&block)
    capture do 
      concat content_tag(:h3) do
        yeld
      end
    end 
  end

您的代码块与concat而不是content_tag

尝试使用括号来标识属于哪个位置.

Try using parentheses to identify what belongs where.

concat(content_tag(:h3) do
  yield
end)