Module: Elasticsearch::Model::Adapter::ActiveRecord::Callbacks

Defined in:
lib/elasticsearch/model/adapters/active_record.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Handle index updates (creating, updating or deleting documents) when the model changes, by hooking into the lifecycle



70
71
72
73
74
75
76
# File 'lib/elasticsearch/model/adapters/active_record.rb', line 70

def self.included(base)
  base.class_eval do
    after_commit lambda { __elasticsearch__.index_document  },  on: :create
    after_commit lambda { __elasticsearch__.update_document },  on: :update
    after_commit lambda { __elasticsearch__.delete_document },  on: :destroy
  end
end