1

我试图让进口商在进口期间选择一个集合选择选项。现在导入器可以工作,但是它在导入过程中没有选择模型类型。

我的架构:

  create_table "hardwares", force: :cascade do |t|
    t.string "serialnumber"
    t.string "modelnumber"
    t.string "location"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.integer "poc_id"
    t.integer "modeltype_id"
    t.index ["modeltype_id"], name: "index_hardwares_on_modeltype_id"
    t.index ["poc_id"], name: "index_hardwares_on_poc_id"
  end

  create_table "modeltypes", force: :cascade do |t|
    t.string "mtype"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "pocs", force: :cascade do |t|
    t.string "name"
    t.string "address"
    t.string "facility"
    t.string "phone"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

硬件.rb

class Hardware < ApplicationRecord
  validates_uniqueness_of :serialnumber
  def self.import(file)
    if file == nil
    else
      CSV.foreach(file.path, headers: true) do |row|
        Hardware.create row.to_hash
      end
    end
  end
end

在我的硬件控制器中导入 Def:

def import
    Hardware.import(params[:file])
    redirect_to hardwares_url, notice: 'Hardware was successfully imported.'
end

CSV 文件

serialnumber,modelnumber,location,poc_id,modeltype_id
S123,M1,deployed,Joe,Dell
S456,M2,local,Shmoe,HP

当我运行导入器时,它会填写序列号和型号,并忽略位置、poc_id 和 modeltype_id。如何在导入期间使用下拉菜单。本质上,我希望它在下拉列表中搜索匹配项并在导入时选择它。

4

0 回答 0