Created
March 27, 2014 21:01
-
-
Save kulte/9818682 to your computer and use it in GitHub Desktop.
Using ActiveRecord::Callback and wrapping your create with a transaction will execute your after_create before the transaction finishes.
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
class User < ActiveRecord::Base | |
after_create :send_welcome_email | |
private | |
def send_welcome_email | |
UserMailer.welcome_email(self).deliver | |
end | |
end | |
User.transaction do | |
User.create(email: '[email protected]') | |
sleep 10 | |
raise ActiveRecord::Rollback | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment