I would like to import csv file into my database. I am using Ruby 1.8.7 and Rails 3.2.13 and the gem 'csv_importer'.
I am going to fetch productname and release_date from csv file
In my controller
def import
csv_text = File.read('test.csv')
csv = CSV.parse(csv_text, :headers => true)
csv.each do |row|
puts row #getting entire values from csv
puts row['productname'] #getting error
end
If I print row/row[0], I am getting entire values from csv file as
productname,release_date
xxx,yyy
in my log.
If I print row['productname'], I am getting error as can't convert String into Integer.
How can I rectify this error?