本文介绍了用concat的Erubis阻止助手抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个帮助块的人,这是我正在做的一个简单示例:

I have a couple of block helpers, here's a simple example of what I'm doing:

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

    content = "
      <div class=\"foo\" id=\"#{foo}\">
        #{data}
      </div>"
    concat( content )
end

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

I'm just trying out erubis and it's giving me the following error:

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.<<

删除对concat的调用会删除该错误,但最终导致未渲染我的包装器

Removing the call to concat removes the error but ends up with my wrapper not being rendered

使用:

  • Rails 2.3.5
  • Erubis 2.6.5
  • 并尝试了 this gem 帮助Erubis(虽然是2.6.4)和Rails 2.3一起玩起来更好
  • Rails 2.3.5
  • Erubis 2.6.5
  • And tried this gem that helps Erubis (though 2.6.4) and Rails 2.3 play better together

推荐答案

自Erubis 2.7.0起,您可以通过以下方式利用:bufvar选项:

since Erubis 2.7.0 you can exploit the :bufvar option in this way:

Erubis::Helpers::RailsHelper.init_properties = {:bufvar => '@output_buffer'}

这篇关于用concat的Erubis阻止助手抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 08:41