Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails, using the dirty or changed? flag with after_commit

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?

like image 590
AnApprentice Avatar asked Aug 23 '11 01:08

AnApprentice


1 Answers

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

like image 117
Yoni Avatar answered Oct 25 '22 11:10

Yoni