Erubis 块助手通过 concat 抛出错误

发布于 2024-08-13 17:49:38 字数 748 浏览 7 评论 0原文

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浅忆 2024-08-20 17:49:38

实际上使用 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! )

牵你的手,一向走下去 2024-08-20 17:49:38

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

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

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

Erubis::Helpers::RailsHelper.init_properties = {:bufvar => '@output_buffer'}
一花一树开 2024-08-20 17:49:38

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.

简单爱 2024-08-20 17:49:38

添加

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文