Commit bacb7c56 by Đường Sỹ Hoàng

Fix error handler

parent 86bdeff2
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_12_10_035904) do
ActiveRecord::Schema.define(version: 2019_12_05_082359) do
create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name"
......@@ -66,8 +66,6 @@ ActiveRecord::Schema.define(version: 2019_12_10_035904) do
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "code"
t.string "location"
t.string "company_name"
end
create_table "user_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
......
require "csv"
namespace :import_job_csv do
namespace :job do
desc "Import CSV file into database"
task import_job: :environment do
task import_csv: :environment do
CSV.foreach("db/Venjob.csv", headers: true) do |row|
company_params = {
email: row["Contact email"],
name: row["Company name"],
address: row["Company address"],
code: row["Company id"]
email: row["contact email"],
name: row["company name"],
address: row["company address"],
code: row["company id"]
}
Company.create!(company_params)
rescue
import_company_logger = ActiveSupport::Logger.new("log/import_company.log")
import_company_logger.info "Skip #{row}"
next
job_params = {
company_id: Company.find_by(code: row["Company id"]).id,
location: row["Work place"],
title: row["Name"],
description: row["Description"],
position: row["Level"],
salary: row["Salary"],
requirement: row["Requirement"]
company_id: Company.find_by(code: row["company id"]).id,
title: row["name"],
description: row["description"],
position: row["level"],
salary: row["salary"],
requirement: row["requirement"]
}
Job.create!(job_params)
end
rescue
import_company_logger = ActiveSupport::Logger.new("log/import_job.log")
import_company_logger.info "Skip #{row}"
import_logger = ActiveSupport::Logger.new("log/import.log")
import_logger.info "Skip #{row}"
next
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment