Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Created August 20, 2015 20:59
Show Gist options
  • Save cheeyeo/1f2b325412942cf89508 to your computer and use it in GitHub Desktop.
Save cheeyeo/1f2b325412942cf89508 to your computer and use it in GitHub Desktop.
ActiveRecord Transactions
ActiveRecord::Base.transaction do
@order.destroy!
@user.save!
end
# calling the bang methods will raise an exception and cause the transaction not to occur if errors exist. calling save and non-bang will not raise
# any errors at all
* Each transaction opens up a new database connection
* AR Callbacks for working with transactions: after_commit and after_rollback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment