i have a code that works fine with ruby 1.87 but dont works with ruby 1.9. It says that CSV::Writer is undeclared but it still part of the rdoc. Does the csv api changed, after the fastercsv merge, or not?
my code:
require 'csv'
def self.export_csv
file_name = File.join(RAILS_ROOT, 'public','csv',"#{start_date_f}_#{end_date_f}.csv")
return file_name if File.exist?(file_name)
@results = find(:all)
header_row = []
outfile = File.open(file_name, 'wb')
CSV::Writer.generate(outfile) do |csv|
header_row = ['gateway_id','created', 'gateway_status_id', 'panel_id', 'panel_status','volts_out', 'amps_out', 'temp','aid' ,'sid', 'pisid']
csv << header_row
end
end
The error that i receive: NameError: uninitialized constant CSV::Writer
Note that require 'csv' is there. i try it in my console, when i do the require 'csv', it works, but as soon as i call CSV::Writer i receive that error.
This code works fine with ruby 1.87, so it makes me think that it is a ruby 1.9 csv problem since it was merged with fasterCSV.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…