I'm writing an import routine that will allow a user to upload a CSV file to load their database. Each row of the CSV corresponds to a model.
I'm using FasterCSV to read the file and split the data into individual models, which is working great. I'm just having trouble deciding on the best approach to handle errors.
Right now I have this going, but it really seems wrong to me:
def import(collection)
begin
self.transaction do
collection.collect{|object| object.save!}
end
rescue ActiveRecord::RecordInvalid => invalid
return false
end
return true
end
Is there a better way to save a collection of models?