没有将 Symbol 隐式转换为 Integer

no implicit conversion of Symbol into Integer

我正在尝试将文件导入 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

这是我的 "deta" 控制器:

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

你们的关系是has_many。因此,accepts_nested_attributes_for 需要一个 数组 。你给它一个散列。这就是错误的根源。给它一个数组。