I have the following in my controller:
private
def csv_to_array(file)
csv = CSV::parse(File.open(file, 'r') {|f| f.read })
fields = csv.shift
csv.collect { |record| Hash[*fields.zip(record).flatten ] }
end
And it throws this issue:
NameError (uninitialized constant FController::CSV):
app/controllers/f_controller.rb:27:in `csv_to_array'
app/controllers/f_controller.rb:9:in `import'
It's my understanding that csv
is included by default in the ruby toolkit, thus not needing to be required. What's causing this issue?
The CSV library is part of the ruby standard library; it is not a gem (i.e. a third party library).
It is in the standard library, but you still have to require it:
require 'csv'
This is one of the differences betweeen core and std-lib.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With