Skip to content

Instantly share code, notes, and snippets.

@dreamr
Forked from Mikr0Tik/person.rb
Created January 5, 2010 09:26
Show Gist options
  • Save dreamr/269269 to your computer and use it in GitHub Desktop.
Save dreamr/269269 to your computer and use it in GitHub Desktop.
class Person < ActiveRecord::Base
before_save :before_save_foo, :before_save_bar
before_create :before_create_claat
before_validation :before_validation_bar
after_save :after_save_clean_skip_callbacks
attr_accessor :skip_callbacks
SKIPPABLE_CALLBACKS = [:before_save_foo, :before_save_bar]
SKIPPABLE_CALLBACKS.each do |cb|
define_method(cb) do
return if skip_callbacks
end
end
def before_save_foo
# stuff if callback isnt skipped
end
..
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment