Ruby on rails overide reindex searchkick方法错误:NoMethodError(super:no超类方法`reindex';for#<;searchkick::RecordIndexer
我们正试图超越Searchkick的重新索引方法,以避免在使用本地环境时重新索引 因此,我们创建了一个初始值设定项/record_indexer.rb: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
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方法,但看起来我应该这样做!