Last active
November 6, 2016 16:44
-
-
Save adammiribyan/66c5ca2aaae6ef626e709a2a634f86ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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