I need to do some processing after a form is submitted that ends up saving multiple records in multiple tables. Since I need it to be all-or-nothing, I wrapped it in a transaction block. The block seems to work just fine, however I don't know how I can check whether or not the transaction was successful so I can return an appropriate response.
...
# Start a transaction block so we can back out if anything fails
ActiveRecord::Base.transaction do
# Journal Entry for from_account
gle = from_account.gl_journal_entries.create(....)
# Journal Line (x2)
gle.gl_journal_lines.create(....)
gle.gl_journal_lines.create(....)
# Journal Entry for to_account
gle = to_account.gl_journal_entries.create(....)
# Journal Line (x2)
gle.gl_journal_lines.create(....)
gle.gl_journal_lines.create(....)
end
# return something based on success/failure of transaction
...