• Rails 上传CSV数据


    def upload(file_name)
      csv = IO.read(file_name).split("
    ")
    
      csv[1..-1].map do |x|
        data = x.split(',')
        sid = data[0].gsub(/"/, '')
        puts sid
        current_term = data[1].gsub(/"/, '').chop
        number_of_payments = data[2].gsub(/"/, '').chop
    
        Account.find_by(id: sid)&.update_columns current_term: current_term, number_of_payments: number_of_payments
      rescue StandardError => e
        puts data
        puts e.message
        next
      end
    end
    
    upload('DOC-2021.csv')
  • 相关阅读:
    MySQL Create table as / Create table like
    Oracle CAST() 函数 数据类型的转换
    day 12
    day 11
    day 10
    day 9
    day 8
    day 7
    day 6
    day 5
  • 原文地址:https://www.cnblogs.com/iwangzheng/p/15421735.html
Copyright © 2020-2023  润新知