1.在rails中解析如下所示的csv文件:
require 'csv'
require 'cmess/guess_encoding'
require 'iconv'
def parse_csv (file_name)
charset = guess_encoding file_name
csv=nil
File.open(file_name, "rb", :external_encoding => charset, :internal_encoding => "UTF-8") { |f| csv = f.read }
Rails.logger.error("File read csv:#{csv}")
csv=Iconv.conv("utf-8", charset, csv) unless charset == "UTF-8"
Rails.logger.error("Iconv conv csv:#{csv}")
rows = CSV.parse(csv, :col_sep => ",")
Rails.logger.error("CSV parse csv:#{rows}")
rows
end
2.Config / application.eb config:
require File.expand_path('../boot', __FILE__)
require 'csv'
require 'rails/all'
3.在开发下它将打印所有3个日志并正常工作,但它只打印生产中的前2个日志,似乎CSV.parse在这里不起作用开发,我很难找到原因,有人知道这里发生了什么吗?