Created
October 28, 2010 07:31
-
-
Save joshed-io/650842 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
class TouchParentObserver < ActiveRecord::Observer | |
observe MyModel, MyOtherModel | |
[:create, :update, :destroy].each do |action| | |
define_method("after_#{action}") do |record| | |
touch_parents_of_observed(record, action) | |
end | |
end | |
private | |
def touch_parents_of_observed(record, action) | |
unless record.skip_observation_on.include?(action) | |
record.send("observed_parents_to_touch").compact.each do |observed_parent| | |
observed_parent.update_attributes!(:updated_at, Time.now) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment