Skip to content

Instantly share code, notes, and snippets.

@adammiribyan
Last active November 6, 2016 16:44
Show Gist options
  • Save adammiribyan/66c5ca2aaae6ef626e709a2a634f86ff to your computer and use it in GitHub Desktop.
Save adammiribyan/66c5ca2aaae6ef626e709a2a634f86ff to your computer and use it in GitHub Desktop.
class ImportsController < ApplicationController
#...
def create
read_csv.each do |row|
attributes = row.to_h.map { |k, v| [attributes_map[k], v] }.to_h
attributes[:address] = "#{row['ulice']}, #{row['okres']}, #{row['misto']} #{row['psc']}"
attributes = attributes.reject { |k, v| k == nil }
Student.create_with(attributes).find_or_create_by(rodne_cislo: attributes[:rodne_cislo])
end
redirect_to students_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment