views:

204

answers:

2

Hi,

is there a way to get the original value that an ActiveRecord attribute (=the value that was loaded from the database)?

I want something like this in an observer

before_save object
  do_something_with object.original_name
end

The task is to remove the object from a hash table (in fact, move it to another key in the table) upon updating.

+6  A: 

Appending "_was" to your attribute will give you the previous value.

Vincent
Thanks, exactly what I was looking for!
Leonid Shevtsov
A: 

ActiveRecord's attributes_before_type_cast method returns a hash of attributes before typecasting and deserialization have occurred.

John Topley