Commit f3cf955b by Mai Hoang Thai Ha

fixed view

parent a36e20ca
// Top page // Top page
// search // search
// banner
.banner {
background-image: url('banner.jpg');
min-height: 200px;
background-repeat: no-repeat;
background-size: cover;
}
// latest-job // latest-job
......
...@@ -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.includes(:company).page(params[:page]).per(20) @jobs = Job.includes(:company, :cities_jobs, :cities).page(params[:page]).per(Job::JOB_PER_PAGE)
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.includes(:company).page(params[:page]).per(20) @jobs = @target.jobs.includes(:company, :cities_jobs, :cities).page(params[:page]).per(Job::JOB_PER_PAGE)
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)
......
...@@ -8,7 +8,7 @@ class City < ApplicationRecord ...@@ -8,7 +8,7 @@ class City < ApplicationRecord
validates :slug, presence: true, uniqueness: { case_sensitive: true } validates :slug, presence: true, uniqueness: { case_sensitive: true }
def self.top_jobs 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.take(TOP_JOB_COUNT)
end end
def self.job_quantity_by_region def self.job_quantity_by_region
......
...@@ -6,7 +6,7 @@ class Industry < ApplicationRecord ...@@ -6,7 +6,7 @@ class Industry < ApplicationRecord
validates :slug, presence: true, uniqueness: { case_sensitive: true } validates :slug, presence: true, uniqueness: { case_sensitive: true }
def self.top_jobs 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.take(TOP_JOB_COUNT)
end end
def self.job_quantity_by_industry def self.job_quantity_by_industry
......
class Job < ApplicationRecord class Job < ApplicationRecord
LATEST_JOBS_LIMIT = 5 LATEST_JOBS_LIMIT = 5
JOB_PER_PAGE = 20
has_and_belongs_to_many :industries has_and_belongs_to_many :industries
has_and_belongs_to_many :cities has_and_belongs_to_many :cities
......
...@@ -20,10 +20,14 @@ ...@@ -20,10 +20,14 @@
= 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| - city_list = job.cities
/ li - city_list.each_with_index do |city, i|
/ = city.name span
= city.name
- if i != city_list.length - 1
span.mx-1
| |
.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
......
ruby: ruby:
city_list = @job.cities city_list = @job.cities
industry_list = @job.industries
/ html / html
.container.my-5 .container.my-5
...@@ -12,18 +13,22 @@ ruby: ...@@ -12,18 +13,22 @@ ruby:
- city_list.each_with_index do |city, i| - city_list.each_with_index do |city, i|
= link_to job_list_path(model: :city, slug: city.slug), class: 'text-decoration-none text-info' do = link_to job_list_path(model: :city, slug: city.slug), class: 'text-decoration-none text-info' do
= city.name = city.name
= ' | ' if i != city_list.length - 1 - if i != city_list.length - 1
span.mx-1.text-info
| |
span.d-block.mx-2 span.d-block.mx-2
| > | >
- industry_list = @job.industries
- industry_list.each_with_index do |industry, i| - industry_list.each_with_index do |industry, i|
= link_to job_list_path(model: :industry, slug: industry.slug), class: 'text-decoration-none text-info' do = link_to job_list_path(model: :industry, slug: industry.slug), class: 'text-decoration-none text-info' do
= industry.name = industry.name
= ' | ' if i != industry_list.length - 1 - if i != industry_list.length - 1
span.mx-1.text-info
| |
span.d-block.mx-2 span.d-block.mx-2
| > | >
= @job.title = @job.title
hr.my-4 hr.my-4
/ job details / job details
.job-detail.my5 .job-detail.my5
.job-apply.d-flex.align-items-center.justify-content-between .job-apply.d-flex.align-items-center.justify-content-between
...@@ -36,11 +41,15 @@ ruby: ...@@ -36,11 +41,15 @@ ruby:
.col-4 .col-4
ul.list-unstyled ul.list-unstyled
li li
strong strong.d-block
| Location | Location
- @job.cities.each do |city| - city_list = @job.cities
p - city_list.each_with_index do |city, i|
span
= city.name = city.name
- if i != city_list.length - 1
span.mx-1
||
li li
strong strong
| Salary | Salary
...@@ -69,7 +78,7 @@ ruby: ...@@ -69,7 +78,7 @@ ruby:
strong strong
| Expiration date | Expiration date
p p
= @job.expiration_date = @job.expiration_date.in_time_zone("Hanoi").to_date
.job-benefits.my-4 .job-benefits.my-4
h3 h3
| Benefits | Benefits
......
...@@ -2,7 +2,7 @@ doctype html ...@@ -2,7 +2,7 @@ doctype html
html html
head head
title title
=full_title(yield(:title)) = full_title(yield(:title))
meta[name='viewport' content='width=device-width,initial-scale=1' charset='utf-8'] meta[name='viewport' content='width=device-width,initial-scale=1' charset='utf-8']
= csrf_meta_tags = csrf_meta_tags
= csp_meta_tag = csp_meta_tag
......
- provide(:title, 'Home page') - provide(:title, 'Home page')
/ search box / search box
.container .container
.row.text-center .banner.d-flex.justify-content-center.align-items-center
.col .row
h2.my-4 .col
| Total: #{pluralize(@total_job, "job")} h2.text-white
| Total: #{pluralize(@total_job, "job")}
= render 'shared/search' = render 'shared/search'
/ latest job / latest job
.latest-job.mb-5 .latest-job.mb-5
.container.mb-5 .container.mb-5
...@@ -21,10 +23,13 @@ ...@@ -21,10 +23,13 @@
| Salary: | Salary:
= job.salary = job.salary
.job-locations .job-locations
ul - city_list = job.cities
- job.cities.each do |city| - city_list.each_with_index do |city, i|
li span
= city.name = city.name
- if i != city_list.length - 1
span.mx-1
| |
.job-desc .job-desc
= truncate(simple_format(job.description), escape: false, length: 250) = truncate(simple_format(job.description), escape: false, length: 250)
hr.my-2 hr.my-2
......
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