Skip to content

Instantly share code, notes, and snippets.

@tomharris
Created January 19, 2013 01:07
Show Gist options
  • Save tomharris/4570061 to your computer and use it in GitHub Desktop.
Save tomharris/4570061 to your computer and use it in GitHub Desktop.
Disable ActiveRecord callbacks
class SomeModel
after_save :queue_a_task, unless: lambda { !!@callbacks_disabled }
def do_something_without_queuing_a_task
disable_callbacks!
do_something_that_triggers_callbacks
enable_callbacks!
end
private
def disable_callbacks!
@callbacks_disabled = true
end
def enable_callbacks!
@callbacks_disabled = true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment