I know this question has been asked a lot on this forum but I\'m under a strict deadline and I need some help, so any advice is much appreciated. I\'m new to Ruby on Rails
I've used this one in the past. It takes any type of model.
Works like a charm.
desc "Imports a CSV file into an ActiveRecord table"
task :csv_model_import, :filename, :model, :needs => :environment do |task,args|
lines = File.new(args[:filename]).readlines
header = lines.shift.strip
keys = header.split(',')
lines.each do |line|
params = {}
values = line.strip.split(',')
keys.each_with_index do |key,i|
params[key] = values[i]
end
Module.const_get(args[:model]).create(params)
end
end