Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails overide reindex searchkick方法错误:NoMethodError(super:no超类方法`reindex';for#<;searchkick::RecordIndexer_Ruby On Rails_Ruby_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Searchkick - Fatal编程技术网 elasticsearch,searchkick,Ruby On Rails,Ruby,elasticsearch,Searchkick" /> elasticsearch,searchkick,Ruby On Rails,Ruby,elasticsearch,Searchkick" />

Ruby on rails overide reindex searchkick方法错误:NoMethodError(super:no超类方法`reindex';for#<;searchkick::RecordIndexer

Ruby on rails overide reindex searchkick方法错误:NoMethodError(super:no超类方法`reindex';for#<;searchkick::RecordIndexer,ruby-on-rails,ruby,elasticsearch,searchkick,Ruby On Rails,Ruby,elasticsearch,Searchkick,我们正试图超越Searchkick的重新索引方法,以避免在使用本地环境时重新索引 因此,我们创建了一个初始值设定项/record_indexer.rb: class Searchkick::RecordIndexer def reindex(options= {}) unless Rails.env == 'local' super(options) end end end 当我尝试更新导致“索引记录”重新索引的关联模型时,它会抛出一个NoMethodErr

我们正试图超越Searchkick的重新索引方法,以避免在使用本地环境时重新索引

因此,我们创建了一个初始值设定项/record_indexer.rb:

class Searchkick::RecordIndexer
  def reindex(options= {})
    unless Rails.env == 'local'
      super(options)
    end
  end
end

当我尝试更新导致“索引记录”重新索引的关联模型时,它会抛出一个NoMethodError(super:no superclass method'reindex'for#在代码中,您完全是在用实现替换方法

如果重写方法并要调用原始方法,则有两个选项:

  • 使用别名存储原始方法

    class Searchkick::RecordIndexer
      alias_method :orig_reindex, :reindex
    
      def reindex(options={})
        unless Rails.env == 'local'
          orig_reindex(options)
        end
      end
    end
    
  • 预编模块

    module YourPatch
      def reindex(options={})
        unless Rails.env == 'local'
          super # no need to specify args if it's just pass-through
        end
      end
    end
    
    Searchkick::RecordIndexer.prepend(YourPatch)
    

  • 第一个选项更适合我的需要,因为gem Searchkick会自动在索引的模型上使用.reindex。因为我自己从来没有使用过Searchkick::RecordIndexer类,所以我更喜欢覆盖它。我不知道#alias#u方法,但看起来我应该这样做!