Skip to content

Instantly share code, notes, and snippets.

@steveh
Forked from benschwarz/on_change.rb
Created November 26, 2009 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveh/243417 to your computer and use it in GitHub Desktop.
Save steveh/243417 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