Erubis阻止助手投掷错误与concat

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

def wrap_foo foo, &block data = capture(&block) content = " 
#{data}
" concat( content ) end

我只是在试用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.<< 

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

使用:

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

实际上使用rails_xss插件 ,这是我的最终目标包含一个修复此问题。

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

Erubis和Rails 2.3不能很好地协同工作。 看看这篇文章: http : //daveelkins.com/2009/06/18/making-erubis-264-and-rails-23-work-together/他在github上创建了一个gem,让他们一起工作。

从Erubis 2.7.0开始,您可以通过以下方式利用:bufvar选项:

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

添加

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

to config / initializers / erubis.rb为我修复了它