I have this rake
task where I'm trying to import a CSV file into my db. Some reason it doesn't just finish, but instead throws an error on the very last line. I tried stopping it earlier but it still throws the same error. I also made sure there weren't any other lines past the last valid value. To import
I'm using the activerecord-import
gem. See my code below:
desc 'add customer to my db'
task :add_my_db => :environment do
puts "adding to my internal database.. hold the line"
add
end
require 'csv'
require 'pp'
def add
rows_to_insert = []
CSV.foreach("customers.csv", headers: true) do |row|
pp row
rows_to_insert << row
end
Customer.import(rows_to_insert)
end
The error it throws is: ArgumentError: Invalid arguments!
Where did I go wrong?