Suppose I have a excel sheet that contains data to be stored in the db.I used roo gem and inserted the data from excel sheet successfully.Now I am trying to validate. Assume my excel sheet as:
s.no name age
1 abc 12
2 def qwer
3 asd 23
when I upload this sheet, the 2 row data is roll-backed and 1,3 row data is stored in db. What I am trying to do is if rollback operation occurs then the remaining records should not be stored in db.i.e the row 3 data should not be stored as row 2 is roll-backed.Any help is appreciated.Thanks.
An update: Here is my code in controller:
def fetch_excel_data
ex = Roo::Excel.new("/desktop/abc.xls")
ex.default_sheet = ex.sheets[0]
2.upto(ex.last_row) do |line|
name = ex.cell(line,2)
age = ex.cell(line,ex.last_column)
byebug
@product = Product.create(:name => name,:age => age)
@product.save!
flash[:success] = "data is stored successfully"
end
end
I want to roll-back entire excel sheet not only records..Is there any way to do so?