-
-
Save poshboytl/520653 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
module AfterCommit | |
def self.included(base) | |
base.class_eval do | |
[:save, :save!].each do |method| | |
alias_method_chain method, :after_commit | |
end | |
end | |
base.define_callbacks :after_commit, :after_commit_on_create | |
end | |
def save_with_after_commit(*args) | |
previous_new_record = new_record? | |
if result = save_without_after_commit(*args) | |
callback(:after_commit) | |
callback(:after_commit_on_create) if previous_new_record | |
end | |
result | |
end | |
def save_with_after_commit!(*args) | |
previous_new_record = new_record? | |
if result = save_without_after_commit!(*args) | |
callback(:after_commit) | |
callback(:after_commit_on_create) if previous_new_record | |
end | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment