Is there a way to track changes to model on after_commit when a record is created? I have tried using dirty module and was able to track changes when the record was updated, but when record is created changes are not recorded.
You can't use the rails changed?
method, as it will always return false. To track changes after the transaction is committed, use the previous_changes
method. It will return a hash with attribute name as key. You can can then check if your attribute_name is in the hash:
after_commit :foo def foo if previous_changes[attribute_name] #do your task end end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With