Commit ba5171d1 by Xuan Trung Le

fix errors

parent 94090d82
class JobsController < ApplicationController class JobsController < ApplicationController
before_action :set_job, only: [:show] before_action :set_job, only: [:show]
def index def index
@jobs = Job.preload(:company).order(updated_date: :desc).limit(5) @jobs = Job.includes(:company).order(updated_date: :desc).limit(5)
@cities = City.top_cities @cities = City.top_cities
@industries = Industry.top_industries @industries = Industry.top_industries
end end
...@@ -13,21 +13,21 @@ class JobsController < ApplicationController ...@@ -13,21 +13,21 @@ class JobsController < ApplicationController
city = City.find(params[:city_id]) city = City.find(params[:city_id])
@jobs = city.jobs.includes(:company).page(params[:page]).per(20) @jobs = city.jobs.includes(:company).page(params[:page]).per(20)
@result = "jobs/City/#{city.name}" @result = "jobs/City/#{city.name}"
render :action => :job_lists render template: "jobs/job_lists"
end end
def industry def industry
industry = Industry.find(params[:industry_id]) industry = Industry.find(params[:industry_id])
@jobs = industry.jobs.includes(:company).page(params[:page]).per(20) @jobs = industry.jobs.includes(:company).page(params[:page]).per(20)
@result = "jobs/Industry/#{industry.name}" @result = "jobs/Industry/#{industry.name}"
render :template => "jobs/job_lists" render template: "jobs/job_lists"
end end
def company def company
company = Company.find(params[:company_id]) company = Company.find(params[:company_id])
@jobs = company.jobs.page(params[:page]).per(20) @jobs = company.jobs.page(params[:page]).per(20)
@result = "jobs/Company/#{company.name}" @result = "jobs/Company/#{company.name}"
render :template => "jobs/job_lists" render template: "jobs/job_lists"
end end
def set_job def set_job
......
...@@ -4,14 +4,14 @@ class City < ApplicationRecord ...@@ -4,14 +4,14 @@ class City < ApplicationRecord
has_many :cities_jobs has_many :cities_jobs
has_many :jobs, through: :cities_jobs has_many :jobs, through: :cities_jobs
scope :top_cities, -> { select('id, name, jobs_count'). scope :top_cities, -> { have_at_least_one_job.
where('jobs_count > 0').
order(jobs_count: :desc). order(jobs_count: :desc).
limit(9) } limit(9) }
scope :city_list, -> { select('cities.id, cities.name AS name, countries.name AS country_name, cities.jobs_count'). scope :city_list, -> { select('cities.id, cities.name AS name, countries.name AS country_name, cities.jobs_count').
joins(:country). joins(:country).
where('jobs_count > 0'). have_at_least_one_job.
order('jobs_count DESC, name') } order(jobs_count: :desc, name: :asc) }
scope :have_at_least_one_job, -> { where('jobs_count > 0')}
end end
class Industry < ApplicationRecord class Industry < ApplicationRecord
# has_and_belongs_to_many :jobs
has_many :industries_jobs has_many :industries_jobs
has_many :jobs, through: :industries_jobs has_many :jobs, through: :industries_jobs
scope :top_industries, -> { select('id, name, jobs_count'). scope :top_industries, -> { have_at_least_one_job.
where('jobs_count > 0'). order(jobs_count: :desc, name: :asc).
order('jobs_count DESC, name').
limit(9) } limit(9) }
scope :industry_list, -> { select('id, name, jobs_count'). scope :industry_list, -> { have_at_least_one_job.
where('jobs_count > 0'). order(jobs_count: :desc) }
order('jobs_count DESC, name') }
scope :have_at_least_one_job, -> { where('jobs_count > 0')}
end end
<div class="col-md-<%= column %>"> <div class="col-md-<%= column %>">
<div class="job-intro well mr0 mrBot20" id="vietnam"> <div class="job-intro well mr0 mrBot20" id="vietnam">
<h4 class="mr0"><%= link_to city.name, _city_jobs_path(city) %></h4> <h4 class="mr0"><%= link_to city.name, city_jobs_path(city) %></h4>
<p>Jobs: <span class="badge"><%= city.jobs_count %></span></p> <p>Jobs: <span class="badge"><%= city.jobs_count %></span></p>
</div> </div>
</div> </div>
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<%- if city.country_name.eql?(Country::VIETNAM) -%> <%- if city.country_name.eql?(Country::VIETNAM) -%>
<div class="col-md-3 maxH109"> <div class="col-md-3 maxH109">
<div class="job-intro well mr0 mrBot20 maxH89"> <div class="job-intro well mr0 mrBot20 maxH89">
<h4 class="mr0"><%= link_to city.name, _city_jobs_path(city) %></h4> <h4 class="mr0"><%= link_to city.name, city_jobs_path(city) %></h4>
<p>Jobs: <span class="badge"><%= city.jobs_count %></span></p> <p>Jobs: <span class="badge"><%= city.jobs_count %></span></p>
</div> </div>
</div> </div>
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<%- if city.country_name.eql?(Country::ANOTHER) -%> <%- if city.country_name.eql?(Country::ANOTHER) -%>
<div class="col-md-3 maxH109"> <div class="col-md-3 maxH109">
<div class="job-intro well mr0 mrBot20 maxH89"> <div class="job-intro well mr0 mrBot20 maxH89">
<h4 class="mr0"><%= link_to city.name, "#{jobs_path}/city/#{city.id}" %></h4> <h4 class="mr0"><%= link_to city.name, city_jobs_path(city) %></h4>
<p>Jobs: <span class="badge"><%= city.jobs_count %></span></p> <p>Jobs: <span class="badge"><%= city.jobs_count %></span></p>
</div> </div>
</div> </div>
......
<div class="col-md-<%= column %> maxH109"> <div class="col-md-<%= column %> maxH109">
<div class="job-intro well mr0 mrBot20 maxH89"> <div class="job-intro well mr0 mrBot20 maxH89">
<h4 class="mr0"><%= link_to industry.name, _industry_jobs_path(industry) %></h4> <h4 class="mr0"><%= link_to industry.name, industry_jobs_path(industry) %></h4>
<p>Jobs: <span class="badge"><%= industry.jobs_count %></span></p> <p>Jobs: <span class="badge"><%= industry.jobs_count %></span></p>
</div> </div>
</div> </div>
...@@ -4,14 +4,14 @@ ...@@ -4,14 +4,14 @@
<li><a href="/">TOP</a></li> <li><a href="/">TOP</a></li>
<li> <li>
<%- @job.cities.each_with_index do |city, index| -%> <%- @job.cities.each_with_index do |city, index| -%>
<%= "#{index > 0 ? ',' : ''}" %> <%= "#{index > 0 ? ',' : ''}" %>
<%= link_to city.name, _city_jobs_path(city) %> <%= link_to city.name, city_jobs_path(city) %>
<%- end -%> <%- end -%>
</li> </li>
<li> <li>
<%- @job.industries.each_with_index do |industry, index| -%> <%- @job.industries.each_with_index do |industry, index| -%>
<%= "#{index > 0 ? ',' : ''}" %> <%= "#{index > 0 ? ',' : ''}" %>
<%= link_to industry.name, _industry_jobs_path(industry) %> <%= link_to industry.name, industry_jobs_path(industry) %>
<%- end -%> <%- end -%>
</li> </li>
<li><%= @job.name %></li> <li><%= @job.name %></li>
...@@ -20,11 +20,11 @@ ...@@ -20,11 +20,11 @@
<div class="job"> <div class="job">
<div class="col-md-9"> <div class="col-md-9">
<h1>2.<%= @job.name %></h1> <h1>2.<%= @job.name %></h1>
<p>3.<%= link_to @job.company.name, _company_jobs_path(@job.company) %></p> <p>3.<%= link_to @job.company.name, company_jobs_path(@job.company) %></p>
<p>4. Location: <p>4. Location:
<%- @job.cities.each_with_index do |city, index| -%> <%- @job.cities.each_with_index do |city, index| -%>
<%= "#{index > 0 ? ',' : ''}" %> <%= "#{index > 0 ? ',' : ''}" %>
<%= link_to city.name, _city_jobs_path(city) %> <%= link_to city.name, city_jobs_path(city) %>
<%- end -%> <%- end -%>
</p> </p>
<p>5. Salary: <%= @job.salary %></p> <p>5. Salary: <%= @job.salary %></p>
......
Rails.application.routes.draw do Rails.application.routes.draw do
root 'jobs#index'
devise_for :users devise_for :users
get 'jobs/index'
resources :cities, :industries, :jobs do resources :cities, only: [:index, :show]
get 'cities' => 'cities#index' resources :industries, only: [:index, :show]
get 'industries' => "industries#index" resources :jobs do
collection do collection do
get 'city/:city_id' => "jobs#city", as: :_city get 'city/:city_id' => "jobs#city", as: :city
get 'industry/:industry_id' => "jobs#industry", as: :_industry get 'industry/:industry_id' => "jobs#industry", as: :industry
get 'company/:company_id' => "jobs#company", as: :_company get 'company/:company_id' => "jobs#company", as: :company
end end
end end
root 'jobs#index'
end end
class AddIndexToCities < ActiveRecord::Migration[5.1]
def change
add_index :cities, :jobs_count
end
end
class AddIndexToIndustries < ActiveRecord::Migration[5.1]
def change
add_index :industries, :jobs_count
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20171016030017) do ActiveRecord::Schema.define(version: 20171016091830) do
create_table "apply_jobs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| create_table "apply_jobs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.bigint "job_id" t.bigint "job_id"
...@@ -29,6 +29,7 @@ ActiveRecord::Schema.define(version: 20171016030017) do ...@@ -29,6 +29,7 @@ ActiveRecord::Schema.define(version: 20171016030017) do
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "jobs_count", default: 0 t.integer "jobs_count", default: 0
t.index ["country_id"], name: "index_cities_on_country_id" t.index ["country_id"], name: "index_cities_on_country_id"
t.index ["jobs_count"], name: "index_cities_on_jobs_count"
end end
create_table "cities_companies", id: false, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| create_table "cities_companies", id: false, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
...@@ -73,6 +74,7 @@ ActiveRecord::Schema.define(version: 20171016030017) do ...@@ -73,6 +74,7 @@ ActiveRecord::Schema.define(version: 20171016030017) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "jobs_count", default: 0 t.integer "jobs_count", default: 0
t.index ["jobs_count"], name: "index_industries_on_jobs_count"
end end
create_table "industries_jobs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| create_table "industries_jobs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
......
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