method
transaction
v2.2.1 -
Show latest stable
- Class:
ActiveRecord::ConnectionAdapters::DatabaseStatements
transaction(start_db_transaction = true)public
Wrap a block in a transaction. Returns result of block.
1Note
Rollback
To rollback the transaction...
transaction do
unless user.save && company.save
raise raise ActiveRecord::Rollback
end
end
Or - catch anonymous exceptions, roll back and re-throw error
transaction do
user.save
company.save
x = 1/0
rescue
exp = $!
begin
raise ActiveRecord::Rollback
rescue
end
raise exp
end