In after_update, possible to see previous value of record?


#1

I have this situation where in an after_update, I would like to know
the previous value of the record instead of simply being notified the
record has been updated.

For example let’s say I had a table called ‘foo’ which had a field
‘new_flag’. I want to know when the ‘new_flag’ field changes from 0 –

1 in an after_update so I can do some business logic in the
after_update. My problem is in the after_update I don’t know how to
detect if that particular field got updated.

Is there some api call I can use to access the old object?

thanks!
-dan


#2

Use the acts_as_versioned plugin
http://wiki.rubyonrails.com/rails/pages/ActsAsVersioned.
You can use the API that will allow you to call the previous version
object and access its values.