<%= with a block in rails 4

▼魔方 西西 提交于 2020-07-03 09:39:05

问题


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

but that's giving me this error:

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 `'

here's how I'm calling it:

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

and here's my helper:

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

回答1:


Your block is being associated with concat instead of content_tag

Try using parentheses to identify what belongs where.

concat(content_tag(:h3) do
  yield
end)


来源:https://stackoverflow.com/questions/62511665/with-a-block-in-rails-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!