【问题标题】:<%= with a block in rails 4<%= 在rails 4中有一个块
【发布时间】:2020-10-12 03:38:19
【问题描述】:

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

但这给了我这个错误:

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

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 helper actionview


    【解决方案1】:

    您的块与concat 而非content_tag 相关联

    尝试使用括号来标识什么属于哪里。

    concat(content_tag(:h3) do
      yield
    end)
    

    【讨论】:

    • 谢谢,我改变了它,但仍然得到同样的错误,如果我在助手中放置一个byebug,似乎任何时候都没有调用助手。因此,我怀疑问题可能出在 erb 上。在我从&lt;%= 中删除= 时,所以有一个非输出标签调用了助手,我得到了另一个错误:ArgumentError - wrong number of arguments (given 0, expected 1) 当调用capture
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多