Created
April 3, 2013 22:43
-
-
Save andreypronin/5306143 to your computer and use it in GitHub Desktop.
Using previous_changes after after_save, in after_commit. Taken from http://logicalfriday.com/2012/08/21/rails-callbacks-workers-and-the-race-you-never-expected-to-lose/:
Available on every object is a method called previous_changes which contains a hash of attributes that changed the last time the object was saved. Sadly, with this we don’t get…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
after_commit :update_external_email, :if => :email_previously_changed? | |
private | |
def update_external_email | |
# do whatever you need to do | |
end | |
def email_previously_changed? | |
previous_changes[:keys].include?('email') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment