Commit 2f8c9a9a by thanhnd

fix review 20200408 1

parent 704c20ee
Pipeline #559 canceled with stages
in 0 seconds
// Place all the styles related to the cities controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
// Place all the styles related to the industries controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
class IndustriesController < ApplicationController
def index
@all_industry = Industry.all_industries_by_job
@top_industry = Industry.top_industries_by_job
end
end
......@@ -3,20 +3,26 @@ class City < ApplicationRecord
has_many :jobs
validates_presence_of :city_name
TOP_CITY_BY_JOB = 9
def self.top_cities_by_job
City.joins(:jobs).select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order.first(9)
#City.joins(:jobs).select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order.first(TOP_CITY_BY_JOB)
joins(:jobs).select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order.first(TOP_CITY_BY_JOB)
end
def self.top_cities_by_job_nn
City.joins(:jobs).where("cities.area_id = 2").select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order.first(9)
#City.joins(:jobs).where("cities.area_id = 2").select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order.first(TOP_CITY_BY_JOB)
joins(:jobs).where("cities.area_id = 2").select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order.first(TOP_CITY_BY_JOB)
end
def self.all_cities_by_job
City.joins(:jobs).select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order
#City.joins(:jobs).select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order
joins(:jobs).select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order
end
def self.all_cities_by_job_nn
City.joins(:jobs).where("cities.area_id = 2").select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order
#City.joins(:jobs).where("cities.area_id = 2").select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order
joins(:jobs).where("cities.area_id = 2").select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order
end
end
......@@ -3,8 +3,10 @@ class Industry < ApplicationRecord
has_many :jobs
validates_presence_of :industry_name
TOP_INDUSTRY_BY_JOB = 9
def self.top_industries_by_job
Industry.joins(:jobs).select('industries.*, COUNT(jobs.id) as job_count').group('jobs.industry_id').order(:job_count).last(9)
Industry.joins(:jobs).select('industries.*, COUNT(jobs.id) as job_count').group('jobs.industry_id').order(:job_count).last(TOP_INDUSTRY_BY_JOB)
end
def self.all_industries_by_job
......
......@@ -11,7 +11,7 @@
<div id="industry_list" class="container p-5 my-2 bg-secondary text-white">
<font color="red"><b><label > Industry List:</label></b></font>
<% @all_industry.each do |industry| %>
<% @top_industry.each do |industry| %>
<ul>
<li><%= industry.industry_name %> <br /> Total jobs in this industry: <%= industry.job_count %> </li>
</ul>
......
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