Monthly Archives: May 2006

Transactions in Rails

Transactions in Rails are starting to bother me, and quite a lot. Once in a while I dive into my latest application,booki.es, a web application for trading long-term futures using play money.

Rails was fantastic for building my wife’s eCommerce site: fairly static content and not many associations between entities. Rails transactional block was sufficient, something of the sorts of:

Account.transaction do account1.deposit(100) account2.withdraw(100) end

or

Account.transaction(peter, paul) do paul.deposit(350) peter.withdraw(350) end

Even ActiveRecord takes care of the transaction integrity for parent-child relationships, so when you save the parent, all child rows get also saved.…