I have a csv, that contains float numbers with commas except of dots like this "34,21", and I need to parse it in my rake task, I have already tried some solutions like this: Ruby on Rails - Import Data from a CSV file
But none of them doesn't seem to be working properly, they just parse it like 2 fields (32 and 21). Is there a way to fix it with using built-in CSV?
I have already tried this:
task :drugimport, [:filename, :model] => :environment do |task,args|
CSV.foreach(args[:filename], { encoding: "UTF-8", headers: true, header_converters: :symbol,
converters: :all}) do |row|
Moulding.create!(row.to_hash)
end
end
And this one:
require 'smarter_csv'
options = {}
SmarterCSV.process('input_file.csv', options} do |chunk|
chunk.each do |data_hash|
Moulding.create!( data_hash )
end
end
They both look nice and elegant, except of wrong parsing of fields containing commas.
here is my rows, sorry there is russian, but whatever: http://pastebin.com/RbC4SVzz I didn't changed anything in it, so I pasted to pastebin, will be more useful then here, I guess
here is my import log: http://pastebin.com/rzC0h9rS