How to do Database Transactions in Rails

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

2 Responses to “How to do Database Transactions in Rails”

  1. Rene A. Says:

    Thanks for the quick tip! The Official wiki was/is down today – and your blog turned up 2nd place in google when I search “rails transaction”.

  2. jack Says:

    shouldn’t it be ModelName.transaction do

Leave a Reply