All or Nothing Database Transactions
When you are updating multiple records in an all or nothing scenario, you can use Active Record Transactions to ensure that either everything is updated or none of it is updated.
For instance, if you are transferring internet points from one user's account to another user's account, you need to be sure that the transfer balances out. If updating one user is successful, but updating the other fails, then there will be a discrepancy in the data. A transaction will ensure that when any part of the update fails the entire transaction is rolled back (at the database level).
PreviousAllow List Params Anywhere With Strong ParamsNextAssert Two Arrays Have The Same Items With RSpec
Last updated