The days of natively supported object transactions are gone. Object transactions you say? Yeah, that nifty little trick that performs rollbacks not only of the database state, but of the object state as well:
1 2 3 4 |
Account.transaction(from, to) do from.withdraw(100) to.deposit(100) end |
If there was a failure within the transaction block above not only would the database have been rolled back, but the internal state of each object argument (from and to in this case) would have as well.
This was previously deprecated, so if you’re still using it, shame on you. All is not lost, however – you can use bitsweat’s object transaction plugin to get this behavior.
tags: ruby, rubyonrails

Glad to hear this… there have been periodic problems with the presence of a copy of Transaction::Simple in the Rails stuff. Transaction::Simple has been upgraded twice since Rails was released and there appear to have been some conflicts between the version required by PDF::Writer and that included with Rails.
I was surprised to see this, I haven’t been getting any deprecation warnings about Object Transactions, and I use them in almost all my controllers.
I guess I’ll switch over to the plugin, unless there’s a better way to do the following:
Late to the party – but why were these taken off of Rails?
Jared, I don’t think that transaction is actually doing anything. Try this: http://pastie.caboo.se/48280
Jared, what you posted is not an Object Transaction. It’s just a regular transaction block which will remain and work fine. The way to spot the difference is that Object Transactions take objects as parameters:
Account.transaction (obj1, obj2) do
versus
Account.transaction do
Re: Jared’s code: ActiveRecord already wraps inserts, updates and deletes in transactions, so the explicit transaction statement is unnecessary.
Hi. I don’t know if this applies to everyone; I might just have buggy code. However, in order to get object_transactions working I also had to install the transactions-simple gem. I don’t think this is mentioned in the object_transactions plugin README.
is no one going to answer the question of WHY these were taken out!?
Hey Brandon,
Contrary to popular belief, this is not a Rails support forum (nor do I speak with any authority as to the intents or motives of the Rails-core team). I would make a post to the mailing list if you really want to know why this feature was removed.
Sorry!
From the plugin’s website: “It was converted into a plugin since it’s not commonly needed.” http://code.bitsweat.net/svn/object_transactions/README