Alex Rivera | Logout

after_commit for an attribute

Asked 2011-08-19T22:31:15.820
60

I am using an after_commit in my application.

I would like it to trigger only when a particular field is updated in my model. Anyone know how to do that?

Edit
Report

1 Answer

78

Old question, but this is one method that I've found that might work with the after_commit callback (working off paukul's answer). At least, the values both persist post-commit in IRB.

after_commit :callback, 
  if: proc { |record| 
    record.previous_changes.key?(:attribute) &&
      record.previous_changes[:attribute].first != record.previous_changes[:attribute].last
  }
answered 2013-02-27T22:09:29.160

Your Answer