无法将哈希转换为整数(TypeError)

时间:2017-05-12 15:52:10

标签: ruby ruby-on-rails-3 ruby-on-rails-3.2

CSV文件 我在一个目录中有1000个文件。我想调用该目录中的所有CSV文件并执行if条件。如果条件满足,则应打印name否则应打印"nothing"

csv示例:

name,id,address,country,food
A,11,bcvhcbdc,india,biryani

...

require "csv"

path="/logs/*exception_evaluation_summary.csv"

#calling csv files in the directory
Dir.glob(path).each do |f|
  #reading csv files
  csv = CSV.read(f, :headers=>true, :encoding => "bom|utf-8")

  csv.each do |record|
    if (record['id'] != 0 && record['country']=="india" && record['food']=="biryani") 
      print record[name]
    else
      print "nothing"
    end
  end
end

0 个答案:

没有答案