-
-
Save steveh/243417 to your computer and use it in GitHub Desktop.
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
# Use on_change :property { # do stuff here } | |
# to make changes to models after a property has been changed | |
module OnChange | |
def on_change(attribute, &block) | |
after_save do | |
block.call if send("#{attribute}_changed?") | |
end | |
end | |
end | |
ActiveRecord::Base.send(:extend, OnChange) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment