<%=,在导轨4中有一个块 [英] <%= with a block in rails 4

查看:65
本文介绍了<%=,在导轨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)

这篇关于&lt;%=,在导轨4中有一个块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆