没有将符号隐式转换为整数

时间:2017-02-02 23:26:53

标签: ruby-on-rails ruby ruby-on-rails-4 roo

我正在尝试将文件导入excel,但是当我尝试使用相关数据创建记录时,它会向我显示以下错误:

no implicit conversion of Symbol into Integer  

在这一行:

 list.detallelp_attributes = {Articulo: row["Articulo"], Minimo: row["Minimo"], Maximo: row["Maximo"], IdEmpresa: empresa}

这是我用于导入的列表控制器和方法:

 has_many :detallelp, class_name: "Deta", foreign_key: "ListaId"
  accepts_nested_attributes_for :detallelp


  def self.import(file,empresa)#importar
    @errors = []
    spreadsheet = open_spreadsheet(file)
    header = spreadsheet.row(1)
    (2..spreadsheet.last_row).each do |i|

      row = Hash[[header, spreadsheet.row(i)].transpose]
      list = find_by_id(row["id"]) || new
      list.attributes = {id: row["id"], Lista: row["Nombre"], Tipo: row["Tipo"], FechaIni: row["Fecha inicial"], FechaFin: row["Fecha final"], IdEmpresa: empresa}

      list.detallelp_attributes = {Articulo: row["Articulo"], Minimo: row["Minimo"], Maximo: row["Maximo"], IdEmpresa: empresa}

      if list.save
        # stuff to do on successful save
       else
         list.errors.full_messages.each do |message|
           @errors << "Error fila #{i}, columna #{message}"
         end
       end


    end
    @errors #  <- need to return the @errors array
  end

我的方法导入列表控制器:

  def import
    empresa = current_usuario.empresa_id
    @errors = List.import(params[:file], empresa)
    if @errors.present?
      render :errorimportation; #Redirije a dicha vista para mostrar los errores
      return;
    else
      redirect_to listap_path, notice: "listas importadas."
    end
  end

这是我的“详细”控制器:

  belongs_to :list, class_name:"List", foreign_key: "ListaId"

1 个答案:

答案 0 :(得分:1)

您的关系是Assert.True(jsonDataLine[i].AdvertisedStartTime.Value.ToString().Equals(DateTimeOffset.Parse(sqlNodeList[i]["AdvertisedStartTime"].InnerText).UtcDateTime.ToString(), "AdvertisedStartTime didn't match Json ", jsonDataLine[i].AdvertisedStartTime.Value.ToString(), DateTimeOffset.Parse(sqlNodeList[i]["AdvertisedStartTime"].InnerText).UtcDateTime.ToString())); 。因此,has_many需要数组。并且你给它一个哈希值。这是错误的根源。给它一个数组。