Commit 5726665a by nnnghia98

edit jobs_import.rb

parent c8d887e1
...@@ -5,31 +5,26 @@ class JobsImport ...@@ -5,31 +5,26 @@ class JobsImport
jobs = [] jobs = []
job_columns = [:title, :level, :salary, :description, :short_des, job_columns = [:title, :level, :salary, :description, :short_des,
:requirement, :category, :company_id] :requirement, :category, :company_id]
city_jobs = [] join_jobs = []
industry_jobs = []
CSV.foreach(Rails.root.join("lib", "jobss.csv"), headers: true) do |row| CSV.foreach(Rails.root.join("lib", "jobss.csv"), headers: true) do |row|
job_csv = JobCsv.new(row) job_csv = JobCsv.new(row)
jobs << job_csv.csv_attributes jobs << job_csv.csv_attributes
city_jobs << [row["company province"], job_csv.title, job_csv.company_id] join_jobs << [row["company province"], row["category"], job_csv.title, job_csv.company_id]
industry_jobs << [row["category"], job_csv.title, job_csv.company_id]
end end
Job.import job_columns, jobs Job.import job_columns, jobs
puts "Jobs imported" puts "Jobs imported"
city_jobs.each do |city_name, job_title, company_id| join_jobs.each do |city_name,industry_name, job_title, company_id|
job = Job.find_by(title: job_title, company_id: company_id) job = Job.find_by(title: job_title, company_id: company_id)
city = City.find_by(name: city_name) city = City.find_by(name: city_name)
job.city_jobs.create(city_id: city.id) job.city_jobs.create(city_id: city.id)
end
puts "Have data in city_jobs table"
industry_jobs.each do |industry_name, job_title, company_id|
job = Job.find_by(title: job_title, company_id: company_id)
industry = Industry.find_by(name: industry_name) industry = Industry.find_by(name: industry_name)
job.industry_jobs.create(industry_id: industry.id) job.industry_jobs.create(industry_id: industry.id)
end end
puts "Have data in city_jobs table"
puts "Have data in industry_jobs table" puts "Have data in industry_jobs table"
end end
end end
...@@ -5,7 +5,6 @@ Rails.application.routes.draw do ...@@ -5,7 +5,6 @@ Rails.application.routes.draw do
resources :jobs, only: :index resources :jobs, only: :index
devise_for :users devise_for :users
root "tops#index" root "tops#index"
get "tops/index"
namespace :users do namespace :users do
resource :my_page, only: :show resource :my_page, only: :show
end end
......
,nghiann,devops-OptiPlex-3020,02.12.2019 09:27,file:///home/nghiann/.config/libreoffice/4;
\ No newline at end of file
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