Erubis 块助手通过 concat 抛出错误
我有几个块助手,这是我正在做的一个简单示例:
def wrap_foo foo, &block
data = capture(&block)
content = "
<div class=\"foo\" id=\"#{foo}\">
#{data}
</div>"
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 更好地协同工作
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
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.<<
Removing the call to concat
removes the error but ends up with my wrapper not being rendered
Using:
- 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
实际上使用 rails_xss 插件,这是我的最终目标,包含修复为了这。
我只需更改我的助手即可执行此操作
concat( content.html_safe! )
Actually using the rails_xss plugin, which was my ultimate goal contains a fix for this.
I just had to change my helper to do this
concat( content.html_safe! )
从 Erubis 2.7.0 开始,您可以通过以下方式利用 :bufvar 选项:
since Erubis 2.7.0 you can exploit the :bufvar option in this way:
Erubis 和 Rails 2.3 不能很好地协同工作。查看这篇文章:http: //daveelkins.com/2009/06/18/making-erubis-264-and-rails-23-work-together/ 他在 github 上创建了一个 gem,可以让它们一起工作。
Erubis and Rails 2.3 don't work together well. Check out this post: http://daveelkins.com/2009/06/18/making-erubis-264-and-rails-23-work-together/ He has created a gem on github that gets them to work together.
添加
Erubis::Helpers::RailsHelper.init_properties = {:bufvar => '@output_buffer'}
到 config/initializers/erubis.rb 为我修复了它
Adding
Erubis::Helpers::RailsHelper.init_properties = {:bufvar => '@output_buffer'}
to config/initializers/erubis.rb fixed it for me