Commit 16b405da by Xuan Trung Le

fix errors

parent 94090d82
class JobsController < ApplicationController
before_action :set_job, only: [:show]
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
@industries = Industry.top_industries
end
......@@ -13,21 +13,21 @@ class JobsController < ApplicationController
city = City.find(params[:city_id])
@jobs = city.jobs.includes(:company).page(params[:page]).per(20)
@result = "jobs/City/#{city.name}"
render :action => :job_lists
render template: "jobs/job_lists"
end
def industry
industry = Industry.find(params[:industry_id])
@jobs = industry.jobs.includes(:company).page(params[:page]).per(20)
@result = "jobs/Industry/#{industry.name}"
render :template => "jobs/job_lists"
render template: "jobs/job_lists"
end
def company
company = Company.find(params[:company_id])
@jobs = company.jobs.page(params[:page]).per(20)
@result = "jobs/Company/#{company.name}"
render :template => "jobs/job_lists"
render template: "jobs/job_lists"
end
def set_job
......
......@@ -4,14 +4,13 @@ class City < ApplicationRecord
has_many :cities_jobs
has_many :jobs, through: :cities_jobs
scope :top_cities, -> { select('id, name, jobs_count').
where('jobs_count > 0').
scope :top_cities, -> { have_at_least_one_job.
order(jobs_count: :desc).
limit(9) }
scope :city_list, -> { select('cities.id, cities.name AS name, countries.name AS country_name, cities.jobs_count').
joins(:country).
where('jobs_count > 0').
order('jobs_count DESC, name') }
scope :city_list, -> { includes(:country).
have_at_least_one_job.
order(jobs_count: :desc, name: :asc) }
scope :have_at_least_one_job, -> { where('jobs_count > 0')}
end
class Industry < ApplicationRecord
# has_and_belongs_to_many :jobs
has_many :industries_jobs
has_many :jobs, through: :industries_jobs
scope :top_industries, -> { select('id, name, jobs_count').
where('jobs_count > 0').
order('jobs_count DESC, name').
scope :top_industries, -> { have_at_least_one_job.
order(jobs_count: :desc, name: :asc).
limit(9) }
scope :industry_list, -> { select('id, name, jobs_count').
where('jobs_count > 0').
order('jobs_count DESC, name') }
scope :industry_list, -> { have_at_least_one_job.
order(jobs_count: :desc) }
scope :have_at_least_one_job, -> { where('jobs_count > 0')}
end
<div class="col-md-<%= column %>">
<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>
</div>
</div>
......@@ -10,10 +10,10 @@
<div id="vietnam" class="city">
<p><h4>Viet Nam</h4></p>
<%- @cities.each do |city| -%>
<%- if city.country_name.eql?(Country::VIETNAM) -%>
<%- if city.country.name.eql?(Country::VIETNAM) -%>
<div class="col-md-3 maxH109">
<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>
</div>
</div>
......@@ -24,10 +24,10 @@
<div id="international" class="city">
<p><h4>International</h4></p>
<%- @cities.each do |city| -%>
<%- if city.country_name.eql?(Country::ANOTHER) -%>
<%- if city.country.name.eql?(Country::ANOTHER) -%>
<div class="col-md-3 maxH109">
<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>
</div>
</div>
......
<div class="col-md-<%= column %> maxH109">
<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>
</div>
</div>
......@@ -5,13 +5,13 @@
<li>
<%- @job.cities.each_with_index do |city, index| -%>
<%= "#{index > 0 ? ',' : ''}" %>
<%= link_to city.name, _city_jobs_path(city) %>
<%= link_to city.name, city_jobs_path(city) %>
<%- end -%>
</li>
<li>
<%- @job.industries.each_with_index do |industry, index| -%>
<%= "#{index > 0 ? ',' : ''}" %>
<%= link_to industry.name, _industry_jobs_path(industry) %>
<%= link_to industry.name, industry_jobs_path(industry) %>
<%- end -%>
</li>
<li><%= @job.name %></li>
......@@ -20,11 +20,11 @@
<div class="job">
<div class="col-md-9">
<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:
<%- @job.cities.each_with_index do |city, index| -%>
<%= "#{index > 0 ? ',' : ''}" %>
<%= link_to city.name, _city_jobs_path(city) %>
<%= link_to city.name, city_jobs_path(city) %>
<%- end -%>
</p>
<p>5. Salary: <%= @job.salary %></p>
......
Rails.application.routes.draw do
root 'jobs#index'
devise_for :users
get 'jobs/index'
resources :cities, :industries, :jobs do
get 'cities' => 'cities#index'
get 'industries' => "industries#index"
resources :cities, only: [:index, :show]
resources :industries, only: [:index, :show]
resources :jobs do
collection do
get 'city/:city_id' => "jobs#city", as: :_city
get 'industry/:industry_id' => "jobs#industry", as: :_industry
get 'company/:company_id' => "jobs#company", as: :_company
get 'city/:city_id' => "jobs#city", as: :city
get 'industry/:industry_id' => "jobs#industry", as: :industry
get 'company/:company_id' => "jobs#company", as: :company
end
end
root 'jobs#index'
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 @@
#
# 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|
t.bigint "job_id"
......@@ -29,6 +29,7 @@ ActiveRecord::Schema.define(version: 20171016030017) do
t.datetime "updated_at", null: false
t.integer "jobs_count", default: 0
t.index ["country_id"], name: "index_cities_on_country_id"
t.index ["jobs_count"], name: "index_cities_on_jobs_count"
end
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
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "jobs_count", default: 0
t.index ["jobs_count"], name: "index_industries_on_jobs_count"
end
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