ruby on rails - Get changed attributes on after_update callback -
i'm trying make conditional after_update, have following:
after_update |participant| rails.logger.info "#{self.previous_changes} changed." if self.previous_changes.include?(:current_distance) #do stuff ... end end
the logger prints empty hash: {}
how can check attribute has been changed?
i using: participant.update_attribute(:current_distance, distance)
update attribute.
you want use changes
not previous_changes
. still in same save transaction looking in changes
. previous_changes
won't have information until after update completes.
Comments
Post a Comment