Commit 704c20ee by thanhnd

fix review 20200407 1

parent b61c3320
Pipeline #550 failed with stages
in 0 seconds
class CitiesController < ApplicationController
def index
@top_cities_vn = City.top_city_by_job
@top_cities_nn = City.top_city_by_job_nn
@all_cities_vn = City.all_city_by_job
@all_cities_nn = City.all_city_by_job_nn
@top_cities_vn = City.top_cities_by_job
@top_cities_nn = City.top_cities_by_job_nn
@all_cities_vn = City.all_cities_by_job
@all_cities_nn = City.all_cities_by_job_nn
end
end
class IndustriesController < ApplicationController
def index
@all_industry = Industry.all_industry_by_job
@all_industry = Industry.all_industries_by_job
end
end
......@@ -3,19 +3,19 @@ class City < ApplicationRecord
has_many :jobs
validates_presence_of :city_name
def self.top_city_by_job
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)
end
def self.top_city_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)
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)
end
def self.all_city_by_job
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
end
def self.all_city_by_job_nn
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
end
......
......@@ -2,6 +2,12 @@ class Industry < ApplicationRecord
has_many :industry_jobs
has_many :jobs
validates_presence_of :industry_name
scope :top_industry_by_job, ->{joins(:jobs).select('industries.*, COUNT(jobs.id) as job_count').group('jobs.industry_id').order(:job_count).last(9)}
scope :all_industry_by_job, ->{joins(:jobs).select('industries.*, COUNT(jobs.id) as job_count').group('jobs.industry_id').order(:job_count).reverse_order}
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)
end
def self.all_industries_by_job
Industry.joins(:jobs).select('industries.*, COUNT(jobs.id) as job_count').group('jobs.industry_id').order(:job_count).reverse_order
end
end
......@@ -14,14 +14,11 @@
<label><a href="#topcity_vn">Viet Nam</a></label>
<br>
<label><a href="#topcity_nn">International</a></label>
</div>
<div id="topcity_vn" class="container p-5 my-2 bg-secondary text-white">
<font color="red"><b><label > Viet Nam:</label></b></font>
<% @all_cities_vn.each do |city_vn| %>
<% @top_cities_vn.each do |city_vn| %>
<ul>
<li><%= city_vn.city_name %> <br /> Total jobs in this city: <%= city_vn.job_count %> </li>
</ul>
......@@ -31,7 +28,7 @@
<div id="topcity_nn" class="container p-5 my-2 bg-secondary text-white">
<font color="red"><b><label > Nuoc Ngoai:</label></b></font>
<% @all_cities_nn.each do |city_nn| %>
<% @top_cities_nn.each do |city_nn| %>
<ul>
<li><%= city_nn.city_name %> <br /> Total jobs in this city: <%= city_nn.job_count %> </li>
</ul>
......
......@@ -10,7 +10,5 @@
<div id="job_list" class="container p-5 my-2 bg-secondary text-white">
<%= render partial: "jobs" %>
</div>
......@@ -5,11 +5,9 @@
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-warning btn-rounded btn-sm my-0" type="submit">Search</button>
</form>
</div>
<div id="job_detail"class="container p-5 my-2 bg-secondary text-white">
<% if @job_detail.nil? == true %>
<div> This id is not available. </div>
<% else %>
......
Rails.application.routes.draw do
get 'cities', to: 'cities#index'
get 'industries', to: 'industries#index'
resources :cities, only: [:index]
resources :industries, only: [:index]
#get 'jobs', to: 'jobs#index'
resources :jobs, only: [:index]
get 'detail/:id', to: 'jobs#show'
get 'jobs', to: 'jobs#index'
get 'jobs/search' => 'jobs#search', as: :job_search
root 'top_page#index'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
......
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