Skip to content

Instantly share code, notes, and snippets.

@kulte
Created March 27, 2014 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kulte/9818682 to your computer and use it in GitHub Desktop.
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.
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: 'abouttobe@soscrewed.com')
sleep 10
raise ActiveRecord::Rollback
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment