【问题标题】:Rails Import: "No Implicit conversion of string into array"Rails 导入:“没有将字符串隐式转换为数组”
【发布时间】:2018-11-19 17:44:25
【问题描述】:

我正在尝试将电子表格中的值导入表格。我将每一行的新记录添加到数组中,然后导入该数组。我的代码如下:

def import(path)

  spreadsheet = Roo::Spreadsheet.open(path+"Data.xlsx")
  sales = spreadsheet.sheet('Accounts')

  sales = sales.parse(headers: true)
  accounts = []

  sales.each do |row|
    a = HM::NewBusiness.new
    a.dealer_id = row["Dlr #"]
    a.dealer_name = row["Dealer Name"]
    a.duns = row["Duns Name"]
    a.industry = row["Type"]
    a.volume_2016 = row["volume_2016"]
    a.volume_2017 = row["volume_2017"]
    a.volume_2018 = row["volume_2018"]
    a.volume_2019 = row["volume_2019"]

    accounts << a
  end
  pp accounts
  HM::NewBusiness.import(accounts)

end

但是,当我运行 import 时,我得到:

TypeError: no implicit conversion of String into Array

我不知道哪里出错了。任何帮助将不胜感激。

【问题讨论】:

    标签: ruby-on-rails activerecord rake-task roo-gem


    【解决方案1】:

    想通了。问题是我巧合地将方法本身命名为“导入”。简而言之,一个 1d10t 的错误。

    【讨论】:

      猜你喜欢
      • 2017-01-19
      • 1970-01-01
      • 2020-04-03
      • 2014-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-15
      相关资源
      最近更新 更多