debugg csv_import

This commit is contained in:
PEB 2022-05-25 18:37:38 +02:00
parent 06ed744c58
commit cf55be7cfc

View File

@ -68,31 +68,31 @@ class ImportCsv < ApplicationRecord
end end
csv_text = File.read(self.file.path, :encoding => 'UTF-8') csv_text = File.read(self.file.path, :encoding => 'UTF-8')
@csv = CSV.parse(csv_text, :headers => true, :col_sep => ",") @csv = CSV.parse(csv_text, :headers => true, :col_sep => ";")
r = [] r = []
@csv.each do |row| @csv.each do |row|
line = {} line = {}
self.import_csv_champs.each do |import_csv_champ| self.import_csv_champs.each do |import_csv_champ|
if import_csv_champ.header? if import_csv_champ.header?
eval "line['#{import_csv_champ.champ}'] = row[\"#{import_csv_champ.header}\"]" eval "line['#{import_csv_champ.champ}'] = row[\"#{import_csv_champ.header}\"]"
elsif import_csv_champ.value? elsif import_csv_champ.value?
eval "line['#{import_csv_champ.champ}'] = \"#{import_csv_champ.value}\"" eval "line['#{import_csv_champ.champ}'] = #{import_csv_champ.value}"
end end
end end
r << line r << line
end end
return r return r
end end
def load def load
self.table_name.classify.constantize.import_csv(self.charge, self, self.m_odr_id) self.table_name.classify.constantize.import_csv(self.charge, self, self.m_odr_id)
end end