Commit 7204d6e1 by Mai Hoang Thai Ha

add helper to display location and breadcrumb

parent f3cf955b
...@@ -18,10 +18,6 @@ class JobsController < ApplicationController ...@@ -18,10 +18,6 @@ class JobsController < ApplicationController
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, :cities_jobs, :cities).page(params[:page]).per(Job::JOB_PER_PAGE) @jobs = @target.jobs.includes(:company, :cities_jobs, :cities).page(params[:page]).per(Job::JOB_PER_PAGE)
elsif job_params.key?(:search) # search by keywords
wildcard_search = "%#{job_params[:search]}%"
@jobs = Job.where('name ILIKE ? OR postal_code LIKE ?', wildcard_search, wildcard_search)
.page(params[:page]).per(Job::JOB_PER_PAGE)
end end
end end
......
...@@ -2,7 +2,7 @@ class TopController < ApplicationController ...@@ -2,7 +2,7 @@ class TopController < ApplicationController
def index def index
@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
@top_industries = Industry.top_jobs.take(Industry::TOP_JOB_COUNT) @top_industries = Industry.top_jobs
end end
end end
...@@ -7,4 +7,23 @@ module ApplicationHelper ...@@ -7,4 +7,23 @@ module ApplicationHelper
"#{page_title} | #{base_title}" "#{page_title} | #{base_title}"
end end
end end
def show_location(list)
list.map(&:name).join(' | ')
end
def show_breadcrumb(list, model)
a = list.map do |item|
link_to item.name, job_list_path(model: model, slug: item.slug), class: 'mx-1 text-decoration-none text-info'
end
a.join('|').html_safe
end
# breadcrumb
# def show_breadcrumb(job)
# a = link_to 'Home', root_path, class: 'text-decoration-none text-info mx-1 '
# span = tag.span '>', class: 'mx-1'
# arr = [a, show_item(job.cities, :city), show_item(job.industries, :industry), job.title]
# arr.join(span).html_safe
# end
end end
...@@ -22,12 +22,7 @@ ...@@ -22,12 +22,7 @@
| Salary: #{job.salary} | Salary: #{job.salary}
ul.list-unstyled ul.list-unstyled
- city_list = job.cities - city_list = job.cities
- city_list.each_with_index do |city, i| = show_location(city_list)
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
......
...@@ -6,26 +6,14 @@ ruby: ...@@ -6,26 +6,14 @@ ruby:
.container.my-5 .container.my-5
/ breadcrumb / breadcrumb
.breadcrumb .breadcrumb
= link_to root_path, class: 'text-decoration-none text-info' do = link_to 'Home', root_path, class: 'text-decoration-none text-info'
'Home span.mx-1 >
span.d-block.mx-2 .text-info
| > = show_breadcrumb(city_list, :city)
- city_list.each_with_index do |city, i| span.mx-1 >
= link_to job_list_path(model: :city, slug: city.slug), class: 'text-decoration-none text-info' do .text-info
= city.name = show_breadcrumb(industry_list, :industry)
- if i != city_list.length - 1 span.mx-1 >
span.mx-1.text-info
| |
span.d-block.mx-2
| >
- 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
= industry.name
- if i != industry_list.length - 1
span.mx-1.text-info
| |
span.d-block.mx-2
| >
= @job.title = @job.title
hr.my-4 hr.my-4
...@@ -43,13 +31,8 @@ ruby: ...@@ -43,13 +31,8 @@ ruby:
li li
strong.d-block strong.d-block
| Location | Location
- city_list = @job.cities p
- city_list.each_with_index do |city, i| = show_location(city_list)
span
= city.name
- if i != city_list.length - 1
span.mx-1
||
li li
strong strong
| Salary | Salary
...@@ -78,7 +61,7 @@ ruby: ...@@ -78,7 +61,7 @@ ruby:
strong strong
| Expiration date | Expiration date
p p
= @job.expiration_date.in_time_zone("Hanoi").to_date = @job.expiration_date.strftime('%d/%m/%Y')
.job-benefits.my-4 .job-benefits.my-4
h3 h3
| Benefits | Benefits
...@@ -89,11 +72,11 @@ ruby: ...@@ -89,11 +72,11 @@ ruby:
.job-desc.my-4 .job-desc.my-4
h3 h3
| Description | Description
= @job.description.html_safe() = @job.description.html_safe
.job-req.my-4 .job-req.my-4
h3 h3
| Requirement | Requirement
= @job.requirement.html_safe() = @job.requirement.html_safe
.job-info.my-4 .job-info.my-4
h3 h3
| Other info | Other info
......
...@@ -24,12 +24,7 @@ ...@@ -24,12 +24,7 @@
= job.salary = job.salary
.job-locations .job-locations
- city_list = job.cities - city_list = job.cities
- city_list.each_with_index do |city, i| = show_location(job.cities)
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-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