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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 ) 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 Atzen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---