Fix code Import CSV and show Industry, City, Job

parent 8d6e1469
Pipeline #741 failed with stages
in 0 seconds
......@@ -45,3 +45,14 @@
top: 20%;
right: 5%;
}
.row-table{
color: black;
padding: 50px;
margin: 30px;
text-align: center;
border: 2px solid red;
}
table{
width: 100%;
}
\ No newline at end of file
class TopPagesController < ApplicationController
def index
@total_jobs = Job.ids
@total_jobs = Job.all
@jobs = Job.limit(5).order(created_at: :desc)
@companies = Company.all
@total_cities = CityJob.all.group('city_id').count
@jobs_of_cities = CityJob.limit(9).group('city_id').order('Count(*) DESC').count
@jobs_of_industries = IndustryJob.limit(9).group('industry_id').order('Count(*) DESC').count
@index = 0
end
end
class City < ApplicationRecord
has_many :city_jobs
has_many :jobs, through: :city_jobs
end
class CityJob < ApplicationRecord
belongs_to :city
belongs_to :job
end
<% @jobs_of_cities.each do |city, count_job| %>
<% @index += 1 %>
<% if @index % 3 == 0 %>
<td class="row-table">
<div class="city-name"><strong><%= City.find(city).name %></strong></div>
<div class="count-job"><%= count_job %></div>
</td>
</tr>
<% else %>
<td class="row-table">
<div class="city-name"><strong><%= City.find(city).name %></strong></div>
<div class="count-job"><%= count_job %></div>
</td>
<% end %>
<% end %>
\ No newline at end of file
<% @jobs_of_industries.each do |industry, count_job| %>
<% @index += 1 %>
<% if @index % 3 == 0 %>
<td class="row-table">
<div class="industry-name"><strong><%= Industry.find(industry).name %></strong></div>
<div class="count-job"><%= count_job %></div>
</td>
</tr>
<% else %>
<td class="row-table">
<div class="industry-name"><strong><%= Industry.find(industry).name %></strong></div>
<div class="count-job"><%= count_job %></div>
</td>
<% end %>
<% end %>
\ No newline at end of file
......@@ -4,13 +4,13 @@
<div class="job-details">
<div class="title"><strong><%= job.title %></strong></div>
<div><%= job.company_name %></div>
<div class="salary"><i class="fas fa-dollar-sign"></i>Lương: <%= job.salary %></div>
<div><i class="fas fa-map-marker"></i>
<div class="salary">$ Lương: <%= job.salary %></div>
<div>
<% job.cities.each do |city| %>
<%= city.name %>
<% end %>
</div>
<button type="button" class="btn btn-primary" id="button-follow"><i class="fas fa-heart"></i> Follow</button>
<button type="button" class="btn btn-primary" id="button-follow"> Follow</button>
</div>
</div>
<br>
......
......@@ -6,6 +6,12 @@
</div>
<div class="container">
<div class="job-list"><%= render 'layouts/show_jobs' %></div>
<div>
<div class="city-banner">City</div>
</div>
<table class="city-list"><%= render 'layouts/show_cities' %></table>
<div class="city-banner">Industry</div>
<table class="industry-list"><%= render 'layouts/show_industries' %></table>
</div>
......@@ -158,14 +158,18 @@ class Crawler
company_id: company_table.id)
puts job_table.id
end
next if company_table.nil?
find_job = Job.find_by(title: title_job, company_id: company_table.id)
industry = row["category"]
industry_find = Industry.find_by(name: industry)
if industry_find.nil?
if industry_find.nil? && find_job.present?
industry_table = Industry.create!(name: industry)
industry_job_table = IndustryJob.create!(job_id: job_table.id, industry_id: industry_find.id)
else
unless IndustryJob.exists?(job_id: find_job.id, industry_id: industry_find.id)
industry_job_table = IndustryJob.create!(job_id: job_table.id, industry_id: industry_find.id)
end
end
puts job_table.id, title_job, industry, salary
location_data = row["work place"]
location = location_data.gsub('["', '').gsub('"]', '')
......@@ -174,9 +178,10 @@ class Crawler
city_table = City.create!(name: location)
city_job_table = CityJob.create!(job_id: job_table.id, city_id: location_find.id)
else
unless CityJob.exists?(job_id: find_job.id, city_id: location_find.id)
city_job_table = CityJob.create!(job_id: job_table.id, city_id: location_find.id)
end
puts "Location: #{location}"
end
rescue StandardError => e
@mylogger.error "#{e.message}"
end
......
......@@ -60,7 +60,7 @@ class Crontab
location_rel.each do |loc|
city_table = City.find_by(name: loc)
next if city_table.nil?
unless CityJob.exists?(job_id: find_job.id, city_id: city_table.id).nil?
unless CityJob.exists?(job_id: find_job.id, city_id: city_table.id)
puts "Created City: #{find_job.id} - #{city_table.id}.#{loc}"
city_jobs = CityJob.create!(job_id: find_job.id, city_id: city_table.id)
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