Commit a583fb3e by thanhnd

fix review toppage 20200226 2

parent d23eeafb
Pipeline #482 failed with stages
in 0 seconds
class TopPageController < ApplicationController
def index
@total_jobs = Job.count
@latest_jobs = Job.latest_five_job
@top_industries = Industry.top_nine_industry
@top_cities = City.top_nine_city
@latest_jobs = Job.latest_job
@top_industries = Industry.top_industry_by_job
@top_cities = City.top_city_by_job
end
end
......
......@@ -2,5 +2,5 @@ class City < ApplicationRecord
belongs_to :area
has_many :jobs
validates_presence_of :city_name
scope :top_nine_city, ->{joins(:jobs).select('cities.*, COUNT(jobs.id) as jobcount').group('jobs.city_id').order(:jobcount).last(9)}
scope :top_city_by_job, ->{joins(:jobs).select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).last(9)}
end
......@@ -2,5 +2,5 @@ class Industry < ApplicationRecord
has_many :industry_jobs
has_many :jobs
validates_presence_of :industry_name
scope :top_nine_industry, ->{joins(:jobs).select('industries.*, COUNT(jobs.id) as jobcount').group('jobs.industry_id').order(:jobcount).last(9)}
scope :top_industry_by_job, ->{joins(:jobs).select('industries.*, COUNT(jobs.id) as job_count').group('jobs.industry_id').order(:job_count).last(9)}
end
......@@ -7,5 +7,5 @@ class Job < ApplicationRecord
belongs_to :city
belongs_to :company
validates_presence_of :job_name
scope :latest_five_job, ->{order(:last_updated).first(5)}
scope :latest_job, ->{order(:last_updated).first(5)}
end
......@@ -39,9 +39,9 @@
<div id="topindustry" class="container p-5 my-2 bg-secondary text-white">
<font color="red"><b><label > Top Industry:</label></b></font>
<% @top_industries.each do |top_industy| %>
<% @top_industries.each do |top_industry| %>
<ul>
<li><%= top_industy.industry_name %></li>
<li><%= top_industry.industry_name %></li>
</ul>
<% end %>
</div>
......
......@@ -47,26 +47,33 @@ namespace :crawler do
#skip if field blank
next if industry.text.blank?
#insert data to City table:
city_name = location.text.gsub(",", "")
city = City.find_or_create_by(area_id: area.id, city_name: city_name, city_description: "")
city = City.find_by(area_id: area.id, city_name: city_name)
city = City.create(area_id: area.id, city_name: city_name, city_description: "") unless city
#insert data to Industry table
industry = Industry.find_or_create_by(industry_name: industry.text, industry_description: "")
industry_row = Industry.find_by(industry_name: industry.text)
industry_row = Industry.create(industry_name: industry.text, industry_description: "") unless industry_row
#insert data to Companies table
company = Company.find_or_create_by(company_name: company_name.text, company_description: company_intro.text, address: address.text)
company = Company.find_by(company_name: company_name.text)
company = Company.create(company_name: company_name.text, company_description: company_intro.text, address: address.text) unless company
#insert data to Jobs table
job_table = Job.find_or_create_by(area_id: area.id, city_id: city.id , industry_id: industry.id, company_id: company.id, job_name: title.text, salary: salary.text, deadline: deadline.text, level: level.text, experience: experience.text.strip, last_updated: updated_date.text.strip, description: description.text)
job_row = Job.find_by(area_id: area.id, city_id: city.id, industry_id: industry_row.id, company_id: company.id, job_name: title.text)
job_row = Job.create(area_id: area.id, city_id: city.id, industry_id: industry_row.id, company_id: company.id, job_name: title.text, salary: salary.text, deadline: deadline.text, level: level.text, experience: experience.text.strip, last_updated: updated_date.text.strip, description: description.text) unless job_row
#insert data to Industry_Jobs table
IndustryJob.find_or_create_by(industry_id: industry.id , job_id: job_table.id)
unless IndustryJob.exists?(industry_id: industry_row.id, job_id: job_row.id)
IndustryJob.create(industry_id: industry_row.id, job_id: job_row.id)
end
end
list_url = nextpage[0]["href"]
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