Hpricot - неопределенный метод `to_sym 'для nil: NilClass - PullRequest
0 голосов
/ 17 мая 2011

Я недавно сделал обновление пакета, которое в итоге сломало много вещей. Одна из вещей, которую я не смог решить, - это hpricot, который я использую для форматирования текста.

Любые пользователи hpricot когда-либо получали это сообщение об ошибке to_sym для nilClass раньше? спасибо

Ошибка:

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

конфиг / Инициализаторы / 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)

1 Ответ

0 голосов
/ 24 ноября 2011

Попробуйте заменить

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)
...