Sunday 15 September 2013

ruby on rails - Delete a .csv file after import from a server -



ruby on rails - Delete a .csv file after import from a server -

this question has reply here:

deleting files in ruby 2 answers

i'm able import .csv file server want delete after import occurs. have of code in rake task , i'm trying delete incidents.csv file after task completed. here code.

require 'csv' require 'open-uri' namespace :import_incidents_csv task :create_incidents => :environment 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 |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 incidents array , report_nr array hash @report_incident_hash = {} @report_nr_array.each_with_index |value, index| @report_incident_hash[value] = @incident_id_array[index] end #puts @report_incident_hash #---------------------------------------------------------------------------- end end

if can ssh server, seek net/ssh gem , run 'rm' command

ruby-on-rails ruby csv rake

No comments:

Post a Comment