Skip to content

Instantly share code, notes, and snippets.

@benschwarz
Created November 26, 2009 10:44
Show Gist options
  • Save benschwarz/243387 to your computer and use it in GitHub Desktop.
Save benschwarz/243387 to your computer and use it in GitHub Desktop.
# 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