Method: Audited::Audit#undo

Defined in:
lib/audited/audit.rb

#undoObject

Allows user to undo changes



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/audited/audit.rb', line 97

def undo
  case action
  when "create"
    # destroys a newly created record
    auditable.destroy!
  when "destroy"
    # creates a new record with the destroyed record attributes
    auditable_type.constantize.create!(audited_changes)
  when "update"
    # changes back attributes
    auditable.update!(audited_changes.transform_values(&:first))
  else
    raise StandardError, "invalid action given #{action}"
  end
end