Module: ModelsTimeline::ClassMethods

Defined in:
lib/models_timeline/model_additions.rb

Instance Method Summary collapse

Instance Method Details

#map_attributes_and_save(action, attributes = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/models_timeline/model_additions.rb', line 41

def map_attributes_and_save(action, attributes={})
attributes = attributes.map{|a| a.to_s unless a.is_a? String}

model_changes = unless attributes.empty?
 HashWithIndifferentAccess.new self.changes.select{|c| attributes.include?(c)}
else
  self.changes
end

model_changes.delete(:created_at)
model_changes.delete(:updated_at)

Track.create!({
  item_id: self.id,
  model_name: self.class.model_name,
  action: action,
  model_changes: model_changes })
end