Commit ae84c4c6 by nnnghia98

create record in city_jobs

parent 16ebb07b
......@@ -14,7 +14,9 @@
#
class City < ApplicationRecord
has_many :city_jobs
has_many :jobs, through: :city_jobs
scope :vn_cities, -> {where region: "Việt Nam"}
scope :inter_cities, -> {where region: "#"}
has_many :city_jobs
end
......@@ -31,4 +31,6 @@
class Job < ApplicationRecord
belongs_to :company
has_many :city_jobs
has_many :cities, through: :city_jobs
end
......@@ -5,12 +5,20 @@ class JobsImport
jobs = []
job_columns = [:title, :level, :salary, :description, :short_des,
:requirement, :category, :company_id]
city_jobs = []
CSV.foreach(Rails.root.join("lib", "jobss.csv"), headers: true) do |row|
jobs << JobCsv.new(row).csv_attributes
job_csv = JobCsv.new(row)
jobs << job_csv.csv_attributes
city_jobs << [row["company province"], job_csv.title, job_csv.company_id]
end
Job.import job_columns, jobs
puts "Jobs imported"
city_jobs.each do |city_name, job_title, company_id|
job = Job.find_by(title: job_title, company_id: company_id)
city = City.find_by(name: city_name)
job.city_jobs.create(city_id: city.id)
end
end
end
<div class="col-md-3">
<div class="col-show">
<%= city.name %>
<%= (city.jobs.count) %>
</div>
</div>
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