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
task import_job: :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["workplace"],
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,
location: row["Work place"],
title: row["Name"],
description: row["Description"],
position: row["Level"],
salary: row["Salary"],
requirement: row["Requirement"]
}
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
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