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



77
78
79
80
81
82
83
# File 'lib/elasticsearch/model/adapters/active_record.rb', line 77

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