Get full old record before save

30 Views Asked by At

I need to backup a record before save. Not only the changes that were made (I know to do it with Person.name_was) but ALL, COMPLETE record.

I.E. something like Person_was. But there is no such method.

How can I achieve that?

1

There are 1 best solutions below

1
Noam B. On

I ended up with this code:

person_history = PersonHistory.new
person.attributes.except("id", "password").each{ |key, value| eval("person_history.#{key} = person.#{key}_was")}
person_history.save