Commit 57c5bab7 by Đường Sỹ Hoàng

Added rescue

parent 09737968
class AddColumnsToJob < ActiveRecord::Migration[6.0]
def change
add_column :jobs, :location, :string
add_column :jobs, :company_name, :string
end
end
...@@ -5,22 +5,30 @@ namespace :import_job_csv do ...@@ -5,22 +5,30 @@ namespace :import_job_csv do
task import_job: :environment do task import_job: :environment do
CSV.foreach("db/Venjob.csv", headers: true) do |row| CSV.foreach("db/Venjob.csv", headers: true) do |row|
company_params = { company_params = {
email: row["contact email"], email: row["Contact email"],
name: row["company name"], name: row["Company name"],
address: row["company address"], address: row["Company address"],
code: row["company id"] code: row["Company id"]
} }
Company.create!(company_params) Company.create!(company_params)
rescue
import_company_logger = ActiveSupport::Logger.new("log/import_company.log")
import_company_logger.info "Skip #{row}"
next
job_params = { job_params = {
company_id: Company.find_by(code: row["company id"]).id, company_id: Company.find_by(code: row["Company id"]).id,
location: row["workplace"], location: row["Work place"],
title: row["name"], title: row["Name"],
description: row["description"], description: row["Description"],
position: row["level"], position: row["Level"],
salary: row["salary"], salary: row["Salary"],
requirement: row["requirement"] requirement: row["Requirement"]
} }
Job.create!(job_params) Job.create!(job_params)
rescue
import_company_logger = ActiveSupport::Logger.new("log/import_job.log")
import_company_logger.info "Skip #{row}"
next
end end
end 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