Rails transactions are a way to ensure that a set of database operations will only occur if all of them succeed. Otherwise, they will rollback to the previous state of data.
Our examples will demonstrate it in the most useful scenario for transactions: money transfers. In this case, you only want Ted to receive money if John loses the same money. Basic usage
def transfer_money
ActiveRecord::Base.transaction do