How to do Database Transactions in Rails

June 4, 2007

It took me a surprsingly long to time learn how to do transactions in Rails. I assumed it would be dead simple (it is), but try googling for rails transactions. Useless. Especially when compared to something like hibernate transactions.

Anyway, this is how you do it:
transaction do
bob.withdrawal(100)
sally.deposit(100)
end

Source: http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html