ruby-on-rails - Erubis block 助手使用 concat 抛出错误

标签 ruby-on-rails view-helpers erubis

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

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
  • 厄鲁比斯 2.6.5
  • 并尝试过 this gem这有助于 Erubis(虽然 2.6.4)和 Rails 2.3 更好地协同工作
  • 最佳答案

    实际使用 rails_xss plugin ,这是我的最终目标,包含对此的修复。

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

    关于ruby-on-rails - Erubis block 助手使用 concat 抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1850398/

    相关文章:

    带 erubis 模板引擎的 Ruby 2.1

    ruby-on-rails - Ruby 渲染特定变量

    ruby-on-rails - 从 Rails 中查找 postgresql 查询 PID(跟踪查询的 ID)

    javascript - 如何使用 ember-rest Controller 来处理 Rails3 嵌套资源?

    c# - 显示日期时间字符串或空字符串的函数

    zend-framework - 使用 Url View 帮助程序链接时从 URL 中删除参数

    ruby-on-rails - 如何在以 `<%=` 元素结尾的 Rails 中的 ERB 模板中使用 `pre` 修剪前导空格?

    ruby-on-rails - 使用 Redis 作为 Rails 国际化后端

    html - 在 RoR 上使用 Prawn 和 Pdfkit 生成 PDF

    cakephp - CakePHP 中的自定义助手错误