# Transaction

**URL:** <https://www.ruby-forum.com/t/transaction/110251>\
**Category:** Rails\
**Created:** [July 24, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/transaction/110251 "2007-07-24T17:11:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pradeep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f0a364/32.png) [@pradeep](https://www.ruby-forum.com/u/pradeep)\
**Post date:** [July 24, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/transaction/110251/1 "2007-07-24T17:11:15Z")

</div>

Hi all,

I have a scenario where i will uploading data from excel to database. My  
condition for uploading is:

If any of the record has an error all the records should be rolled back.

Plz give me suggestions how to implement if we have a loop.

Thanks,  
Pradeep

---

<div class="post-metadata">

**Author:** ![pradeep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f0a364/32.png) [@pradeep](https://www.ruby-forum.com/u/pradeep)\
**Post date:** [July 26, 2007, 12:46am UTC](https://www.ruby-forum.com/t/transaction/110251/2 "2007-07-26T00:46:13Z")

</div>

Pradeep M. wrote:

> Hi all,
> 
> I have a scenario where i will uploading data from excel to database. My  
> condition for uploading is:
> 
> If any of the record has an error all the records should be rolled back.
> 
> Plz give me suggestions how to implement if we have a loop.

Let’s say you have a ExcelData class which is a subclass of  
ActiveRecord:

ExcelData.transaction do  
theExcelRecords.each do |currentRecord|  
ExcelData.create!( currentRecord )  
end  
end

In this case if any of the currentRecord’s are unable to be saved the  
whole transaction will be rolled back.

I hope this was the information you were looking for.

–  
Cheers,

- Jacob A.
