Skip to content

Instantly share code, notes, and snippets.

@chelseatroy

chelseatroy/import.rb

Last active Sep 20, 2018
Embed
What would you like to do?
Example: Transactional Data Import
class Import
def import_workouts(rows)
errors = []
CSV.foreach(@import_file_path, {headers: true}) do |row|
begin
attributes = row.to_hash
row.create(attributes)
errors += row.failures
rescue StandardError => e
errors << [row.index, row.data, [e.message, *e.backtrace]]
end
end
File.open('import_error_report', 'w') { |file| file.write(errors.join("\n") }
end
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.