Rails 使用数据库事务 (ActiveRecord)

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

my_account = Account.find 3
your_account = Account.find 4

Account.transaction do
  my_account.update_attribute(:balance, my_account.balance-300.00)
  your_account.update_attribute(:balance, your_account.balance+300.00)
end