Commit b7973d66 by thanhnd

done city_list and industry_list

parent 8b4e9b3b
Pipeline #492 failed 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 CitiesController < ApplicationController
def index
@top_cities_vn = City.top_city_by_job
@top_cities_nn = City.top_city_by_job_nn
@all_top_cities_vn = City.all_city_by_job
@all_top_cities_nn = City.all_city_by_job_nn
end
end
class IndustriesController < ApplicationController
def index
@all_industry = Industry.all_industry_by_job
end
end
module CitiesHelper
end
module IndustriesHelper
end
......@@ -2,5 +2,9 @@ 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)}
scope :top_city_by_job, ->{joins(:jobs).select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order.first(9)}
scope :top_city_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(9)}
scope :all_city_by_job, ->{joins(:jobs).select('cities.*, COUNT(jobs.id) as job_count').group('jobs.city_id').order(:job_count).reverse_order}
scope :all_city_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
......@@ -3,4 +3,5 @@ class Industry < ApplicationRecord
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}
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>
<% @all_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>
<% @all_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>
<% @all_industry.each do |industry| %>
<ul>
<li><%= industry.industry_name %> <br /> Total jobs in this industry: <%= industry.job_count %> </li>
</ul>
<% end %>
</div>
Rails.application.routes.draw do
get 'industries/index'
get 'cities/index'
get '/detail/:id', to: 'jobs#show'
get '/joblist', to: 'jobs#index'
get '/citylist', to: 'cities#index'
get '/industrylist', to: 'industries#index'
get '/jobsearch' => '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
require 'test_helper'
class IndustriesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get industries_index_url
assert_response :success
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