Pradeep Maddi 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 )

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.