Hpricot - 未定义的方法“to_sym”对于 nil:NilClass

发布于 2024-11-07 20:04:02 字数 1416 浏览 4 评论 0原文

我最近做了一次捆绑更新,最终破坏了很多东西。我无法解决的问题之一是使用 hpricot 来格式化文本。

之前有 hpricot 用户遇到过这个 to_sym for nilClass 错误吗?谢谢

错误:

ActionView::Template::Error (undefined method `to_sym' for nil:NilClass):
config/initializers/hpricot_text_transform.rb:11:in `text_transform!'

config/initializers/hpricot_text_transform.rb

# By Henrik Nyh <http://henrik.nyh.se> 2007-03-28.
# Based on http://vemod.net/code/hpricot_goodies/hpricot_text_gsub.rb.
# Licensed under the same terms as Ruby.

require "rubygems"
require "hpricot"

module HpricotTextTransform
  module NodeWithChildrenExtension
    def text_transform!(options={}, &block)
      return if defined?(name) and Array(options[:except]).include?(name.to_sym)
      children.each { |c| c.text_transform!(options, &block) }
    end
  end

  module TextNodeExtension
    def text_transform!(options={}, &block)
      content.replace yield(content)
    end
  end

  module BogusETagExtension
    def text_transform!(options={}, &block)
    end
  end
end

Hpricot::Doc.send(:include,  HpricotTextTransform::NodeWithChildrenExtension)
Hpricot::Elem.send(:include, HpricotTextTransform::NodeWithChildrenExtension)
Hpricot::BogusETag.send(:include, HpricotTextTransform::BogusETagExtension)
Hpricot::Text.send(:include, HpricotTextTransform::TextNodeExtension)

I recently did a bundle update which ended up breaking a lot of stuff. One of the things I haven't been able to resolve is with hpricot which I use to format text.

Any hpricot users ever get this to_sym for nilClass error before? thanks

Error:

ActionView::Template::Error (undefined method `to_sym' for nil:NilClass):
config/initializers/hpricot_text_transform.rb:11:in `text_transform!'

config/initializers/hpricot_text_transform.rb

# By Henrik Nyh <http://henrik.nyh.se> 2007-03-28.
# Based on http://vemod.net/code/hpricot_goodies/hpricot_text_gsub.rb.
# Licensed under the same terms as Ruby.

require "rubygems"
require "hpricot"

module HpricotTextTransform
  module NodeWithChildrenExtension
    def text_transform!(options={}, &block)
      return if defined?(name) and Array(options[:except]).include?(name.to_sym)
      children.each { |c| c.text_transform!(options, &block) }
    end
  end

  module TextNodeExtension
    def text_transform!(options={}, &block)
      content.replace yield(content)
    end
  end

  module BogusETagExtension
    def text_transform!(options={}, &block)
    end
  end
end

Hpricot::Doc.send(:include,  HpricotTextTransform::NodeWithChildrenExtension)
Hpricot::Elem.send(:include, HpricotTextTransform::NodeWithChildrenExtension)
Hpricot::BogusETag.send(:include, HpricotTextTransform::BogusETagExtension)
Hpricot::Text.send(:include, HpricotTextTransform::TextNodeExtension)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

素染倾城色 2024-11-14 20:04:02

尝试替换

return if defined?(name) and Array(options[:except]).include?(name.to_sym)

return if defined?(name) and !(name.nil?) and Array(options[:except]).include?(name.to_sym)

Try replacing

return if defined?(name) and Array(options[:except]).include?(name.to_sym)

with

return if defined?(name) and !(name.nil?) and Array(options[:except]).include?(name.to_sym)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文