Created
January 19, 2013 01:07
-
-
Save tomharris/4570061 to your computer and use it in GitHub Desktop.
Disable ActiveRecord callbacks
This file contains hidden or 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 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