This is easy if you use smarter_csv .
All you have to do is the following:
require 'smarter_csv' def import(filename) results = SmarterCSV.process( filename, options_hash ) end
and you need to specify parameters in options_hash according to smarter_csv documentation
There are many useful options, including header manipulation, custom headers, column ignoring, and value type conversion.
If your CSV file is large, you can also combine incoming data for parallel processing.
source share