Commit a36e20ca by Mai Hoang Thai Ha

add includes to action index of job controller

parent 0e3f626d
...@@ -3,7 +3,7 @@ class JobsController < ApplicationController ...@@ -3,7 +3,7 @@ class JobsController < ApplicationController
if job_params.present? if job_params.present?
search search
else else
@jobs = Job.page(params[:page]).per(20) @jobs = Job.includes(:company).page(params[:page]).per(20)
end end
end end
...@@ -17,7 +17,7 @@ class JobsController < ApplicationController ...@@ -17,7 +17,7 @@ class JobsController < ApplicationController
if job_params.key?(:model) && job_params.key?(:slug) # search by model if job_params.key?(:model) && job_params.key?(:slug) # search by model
model = params[:model].classify.constantize model = params[:model].classify.constantize
@target = model.find_by(slug: job_params[:slug]) @target = model.find_by(slug: job_params[:slug])
@jobs = @target.jobs.page(params[:page]).per(20) @jobs = @target.jobs.includes(:company).page(params[:page]).per(20)
elsif job_params.key?(:search) # search by keywords elsif job_params.key?(:search) # search by keywords
wildcard_search = "%#{job_params[:search]}%" wildcard_search = "%#{job_params[:search]}%"
@jobs = Job.where('name ILIKE ? OR postal_code LIKE ?', wildcard_search, wildcard_search) @jobs = Job.where('name ILIKE ? OR postal_code LIKE ?', wildcard_search, wildcard_search)
......
...@@ -3,6 +3,6 @@ class TopController < ApplicationController ...@@ -3,6 +3,6 @@ class TopController < ApplicationController
@total_job = Job.count @total_job = Job.count
@latest_jobs = Job.latest @latest_jobs = Job.latest
@top_cities = City.top_jobs.take(City::TOP_JOB_COUNT) @top_cities = City.top_jobs.take(City::TOP_JOB_COUNT)
@top_industries = Industry.job_quantity_by_industry.take(Industry::TOP_JOB_COUNT) @top_industries = Industry.top_jobs.take(Industry::TOP_JOB_COUNT)
end end
end end
...@@ -13,8 +13,7 @@ class City < ApplicationRecord ...@@ -13,8 +13,7 @@ class City < ApplicationRecord
def self.job_quantity_by_region def self.job_quantity_by_region
regions.each_with_object({}) do |(name, _), hash| regions.each_with_object({}) do |(name, _), hash|
hash[name.to_sym] = send(name).joins(:jobs).group(:name, :slug) hash[name.to_sym] = send(name).joins(:jobs).group(:name, :slug).count
.order('COUNT(jobs.id) DESC').count
end end
end end
end end
...@@ -5,7 +5,11 @@ class Industry < ApplicationRecord ...@@ -5,7 +5,11 @@ class Industry < ApplicationRecord
validates :slug, presence: true, uniqueness: { case_sensitive: true } validates :slug, presence: true, uniqueness: { case_sensitive: true }
def self.job_quantity_by_industry def self.top_jobs
joins(:jobs).group(:name, :slug).order('COUNT(jobs.id) DESC').count joins(:jobs).group(:name, :slug).order('COUNT(jobs.id) DESC').count
end end
def self.job_quantity_by_industry
joins(:jobs).group(:name, :slug).count
end
end end
...@@ -20,10 +20,10 @@ ...@@ -20,10 +20,10 @@
= link_to job.company.name, '#', class: 'job-company text-decoration-none text-secondary' = link_to job.company.name, '#', class: 'job-company text-decoration-none text-secondary'
p.job-salary.text-success p.job-salary.text-success
| Salary: #{job.salary} | Salary: #{job.salary}
ul.list-unstyled / ul.list-unstyled
- job.cities.each do |city| / - job.cities.each do |city|
li / li
= city.name / = city.name
.job-desc .job-desc
= truncate(simple_format(job.description), escape: false, length: 250) = truncate(simple_format(job.description), escape: false, length: 250)
hr.my-4 hr.my-4
......
- provide(:title, 'Home page') - provide(:title, 'Home page')
/ search box / search box
= render 'shared/search' .container
.row.text-center
.col
h2.my-4
| Total: #{pluralize(@total_job, "job")}
= render 'shared/search'
/ latest job / latest job
.latest-job.mb-5 .latest-job.mb-5
.container.mb-5 .container.mb-5
......
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