Rails, using the dirty or changed? flag with after_commit

AnApprentice picture AnApprentice · Aug 23, 2011 · Viewed 11k times · Source

I heard rails has a dirty/change flag. Is it possible to use that in the after_commit callback?

In my user model I have:

after_commit :push_changes

In def push_changes I would like a way to know if the name field changed. Is that possible?

Answer

Yoni picture Yoni · May 29, 2013

You can use previous_changes in after_commit to access a model's attribute values from before it was saved.

see this post for more info: after_commit for an attribute