Erubis阻止助手投掷错误与concat

DEf*_*ion 6 ruby-on-rails erubis view-helpers

我有几个块助手,这是我正在做的一个简单的例子:

def wrap_foo foo, &block
    data = capture(&block)

    content = "
      <div class=\"foo\" id=\"#{foo}\">
        #{data}
      </div>"
    concat( content )
end
Run Code Online (Sandbox Code Playgroud)

我只是尝试erubis,它给了我以下错误:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.<<
Run Code Online (Sandbox Code Playgroud)

删除调用以concat删除错误但最终导致我的包装器没有被渲染

使用:

  • Rails 2.3.5
  • Erubis 2.6.5
  • 并尝试了这个宝石,帮助Erubis(虽然2.6.4)和Rails 2.3一起发挥得更好

DEf*_*ion 2

实际上,使用Rails_xss 插件(这是我的最终目标)包含了对此的修复。

我只需要改变我的助手来做到这一点concat( content.html_safe! )