ruby on rails - wrapping non-ActiveRecord actions in an ActiveRecord transaction, will this work? -
i have piece of code creates db records, processes dwolla transaction. want or nothing. if of lines inside transaction block throw exception, first 2 lines (the active record lines) roll back? note, whole thing wrapped in begin/rescue/end i'm concerned 1 point.
user.transaction user.save! record.save! transactionid = dwolla::transactions.send({:destinationid => user.dwolla_id, :amount => amount, :pin => dwollatransaction.get_dwolla_pin}) transac = dwollatransaction.create(user_id: user.id, transaction_id: transactionid, amount: amount) end thanks insight. basically, want make sure our internal records never saved if external api call fails.
yes, long they're raising exceptions when fail, db transaction rolled back, , save!s not committed db.
Comments
Post a Comment