Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Suppress ActiveSupport callbacks
module ActiveSupport::Callbacks::ClassMethods
def without_callbacks(callbacks, &block)
saved = {}
callbacks.each do |callback|
saved[callback] = instance_method(callback)
remove_method(callback) if respond_to?(callback)
define_method(callback){ true }
end
begin
result = yield
ensure
callbacks.each do |callback|
remove_method(callback)
define_method(callback, saved[callback])
end
end
result
end
end
@dblock

This comment has been minimized.

Copy link
Owner Author

commented Jun 4, 2011

I am aware that ActiveSupport has a new clever method of dealing with this, but it has always confused me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.