0
내 서버에서 내 .csv 파일을 가져올 수 있지만 이제는 가져 오기가 완료된 후에 파일을 삭제하기 만하면됩니다. 레이크 작업에 모든 코드가 있으며 작업이 완료된 후 incidents.csv 파일을 삭제하려고합니다. 여기 내 코드가있다.서버에서 가져온 후 .csv 파일 삭제
require 'csv'
require 'open-uri'
namespace :import_incidents_csv do
task :create_incidents => :environment do
puts "Import Incidents"
#csv_text = File.read('/Users/Ben/Sites/ror/LFD/incidents.csv', :encoding => 'windows-1251:utf-8')
csv_text = open("http://www.##########.com/###########/incidents.csv") {|f| f.read}
csv = CSV.parse(csv_text, :headers => true)
@incident_id_array = []
@report_nr_array = []
csv.each do |row|
row = row.to_hash.with_indifferent_access
Incident.create!(row.to_hash.symbolize_keys)
@incident_id_array << Incident.last.id
@report_nr_array << Incident.last.report_nr
end
#------This combines the incidents array and the report_nr array into a hash
@report_incident_hash = {}
@report_nr_array.each_with_index do |value, index|
@report_incident_hash[value] = @incident_id_array[index]
end
#puts @report_incident_hash
#----------------------------------------------------------------------------
end
end