Commit 6a010474 by Ba Toi Dang

Merge branch 'city_list' into 'master'

City list

See merge request !5
parents b36f3848 f8e30777
Pipeline #561 failed with stages
in 0 seconds
class CitiesController < ApplicationController
def index
@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
@top_industry = Industry.top_industries_by_job
end
end
......@@ -2,5 +2,23 @@ class City < ApplicationRecord
belongs_to :area
has_many :jobs
validates_presence_of :city_name
scope :top_city_by_job, ->{joins(:jobs).select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).last(9)}
TOP_CITY_BY_JOB = 9
def self.top_cities_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
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
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
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
......@@ -2,5 +2,14 @@ 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)}
TOP_INDUSTRY_BY_JOB = 9
def self.top_industries_by_job
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
joins(:jobs).select('industries.*, COUNT(jobs.id) as job_count').group('jobs.industry_id').order(:job_count).reverse_order
end
end
<div id="search" class="container p-5 my-2 bg-secondary text-white">
<%= form_tag job_search_path, method: :get do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= button_tag "Search", name: nil %>
</p>
<% end %>
</div>
<div id="city_list"class="container p-5 my-2 bg-secondary text-white">
<font color="red"><b><label > City List:</label></b></font>
<br>
<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>
<% @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>
<% end %>
</div>
<div id="topcity_nn" class="container p-5 my-2 bg-secondary text-white">
<font color="red"><b><label > Nuoc Ngoai:</label></b></font>
<% @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>
<% end %>
</div>
<div id="search" class="container p-5 my-2 bg-secondary text-white">
<%= form_tag job_search_path, method: :get do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= button_tag "Search", name: nil %>
</p>
<% end %>
</div>
<div id="industry_list" class="container p-5 my-2 bg-secondary text-white">
<font color="red"><b><label > Industry List:</label></b></font>
<% @top_industry.each do |industry| %>
<ul>
<li><%= industry.industry_name %> <br /> Total jobs in this industry: <%= industry.job_count %> </li>
</ul>
<% end %>
</div>
......@@ -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
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
resources :top_page
resources :jobs, :only => [:show, :index]
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