Skip to content

Instantly share code, notes, and snippets.

@chebyte
Created December 12, 2012 14:00
Show Gist options
  • Save chebyte/4267907 to your computer and use it in GitHub Desktop.
Save chebyte/4267907 to your computer and use it in GitHub Desktop.
csv.drop(params[:is_column_headings].present? || params[:matched_columns].nil? ? 1 : 0).each_slice(500) do |rows|
ActiveRecord::Base.transaction do # Make sure all record persistance is rolled back if an exception occurs
rows.each do |row|
# load data
columns.values.each_with_index{|named_columns, i| data.merge!(named_columns => row[i]) if named_columns}
# build record
if duplicate_record?(is_skip_duplicates, data, current_user)
row << "This record is potentialy a duplicate and was not #{self.name.split("::")[1].downcase}ed."
status = "errors"
else
status, row = build_record(row, data, current_user, additional_details)
end
results[status.to_sym] << row
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment