Commit cb35c893 by Trịnh Hoàng Phúc

Inprogress fix review 18/05/2020

parent f7159414
Pipeline #630 failed with stages
in 0 seconds
// Place all the styles related to the pages controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
class HomeController < ApplicationController class HomeController < ApplicationController
def index def index
@amount_job = Job.count @amount_job = Job.count
@latest_jobs = Job.includes(:cities, :company).last(Settings.home.limit) @latest_jobs = Job.latest_jobs
@latest_cities = City.includes(:jobs).jobs_count_order_by @latest_cities = City.jobs_count_order_by
@latest_industries = Industry.includes(:jobs).jobs_count_order_by @latest_industries = Industry.jobs_count_order_by
end end
end end
...@@ -14,29 +14,31 @@ class JobsController < ApplicationController ...@@ -14,29 +14,31 @@ class JobsController < ApplicationController
@amount_job = Job.count @amount_job = Job.count
end end
end end
def show def show
@job = Job.includes(:cities, :industries, :company).find_by(id: params[:id]) @job = Job.find_by(id: params[:id])
if @job.present?
@title = @job.title return redirect_to page_404_path if @job.blank?
if user_signed_in?
@apply = Apply.find_by(job_id: params[:id], user_id: current_user.id) if user_signed_in?
@favorite = Favorite.find_by(job_id: params[:id], user_id: current_user.id) @apply = Apply.find_by(job_id: params[:id], user_id: current_user.id)
end @favorite = Favorite.find_by(job_id: params[:id], user_id: current_user.id)
@relate_jobs = Job.includes(:cities, :company).where("company_id = ? and id != ?", @job.company_id, @job.id).order("id DESC").limit(10) end
if cookies[:job_ids_history].nil?
cookies[:job_ids_history] = {value: @job.id, expires: Time.now + 3600} @relate_jobs = Job.related_jobs(@job.company_id, @job.id)
else
arr_job_ids = cookies[:job_ids_history].split(",") if cookies[:job_ids_history].nil?
unless arr_job_ids.include? (@job.id.to_s) cookies[:job_ids_history] = { value: @job.id, expires: Time.now + 3600 }
arr_job_ids.shift if arr_job_ids.count == 10
arr_job_ids << @job.id.to_s
end
cookies[:job_ids_history] = {value: arr_job_ids.join(","), expires: Time.now + 3600}
end
else else
@title = "Job was not found" arr_job_ids = cookies[:job_ids_history].split(",")
unless arr_job_ids.include? (@job.id.to_s)
arr_job_ids.shift if arr_job_ids.count == 10
arr_job_ids << @job.id.to_s
end
cookies[:job_ids_history] = { value: arr_job_ids.join(","), expires: Time.now + 3600 }
end end
end end
def search def search
return redirect_to root_path, alert: "Empty field!" if params[:keyword].blank? return redirect_to root_path, alert: "Empty field!" if params[:keyword].blank?
response = RsolrService.new.query_job("job_title:#{params[:keyword]}", params[:page]) response = RsolrService.new.query_job("job_title:#{params[:keyword]}", params[:page])
......
class PagesController < ApplicationController
def page_404
end
end
module PagesHelper
end
...@@ -8,6 +8,6 @@ class City < ApplicationRecord ...@@ -8,6 +8,6 @@ class City < ApplicationRecord
end end
def self.jobs_count_order_by def self.jobs_count_order_by
@jobs_count_order_by ||= all.sort_by(&:jobs_count).reverse.take(Settings.home.limit + 2) @jobs_count_order_by ||= includes(:jobs).sort_by(&:jobs_count).reverse.take(Settings.home.limit + 2)
end end
end end
...@@ -8,6 +8,6 @@ class Industry < ApplicationRecord ...@@ -8,6 +8,6 @@ class Industry < ApplicationRecord
end end
def self.jobs_count_order_by def self.jobs_count_order_by
@jobs_count_order_by ||= all.sort_by(&:jobs_count).reverse.take(Settings.home.limit + 2) @jobs_count_order_by ||= includes(:jobs).sort_by(&:jobs_count).reverse.take(Settings.home.limit + 2)
end end
end end
class Job < ApplicationRecord class Job < ApplicationRecord
scope :by_cities, -> (city_id) {includes(:cities).where("cities.id = ?", city_id).references(:cities)} scope :by_cities, -> (city_id) {includes(:cities).where("cities.id = ?", city_id).references(:cities)}
scope :by_industries, -> (industry_id) {includes(:industries).where("industries.id = ?", industry_id).references(:industries)} scope :by_industries, -> (industry_id) {includes(:industries).where("industries.id = ?", industry_id).references(:industries)}
scope :by_companies, -> (company_id) {where("company_id = #{company_id}")} scope :by_companies, -> (company_id) {where("company_id = ?", company_id)}
EXPORT_CSV_ATTRIBUTES = %w(title updated_date_job level years_of_experience salary expiration_date).freeze EXPORT_CSV_ATTRIBUTES = %w(title updated_date_job level years_of_experience salary expiration_date).freeze
...@@ -27,4 +27,12 @@ class Job < ApplicationRecord ...@@ -27,4 +27,12 @@ class Job < ApplicationRecord
errors.add(:updated_date_job, "can't be greater than expiration date") errors.add(:updated_date_job, "can't be greater than expiration date")
end end
end end
def self.latest_jobs
@latest_jobs ||= includes(:cities, :company).last(Settings.home.limit)
end
def self.related_jobs(company_id, job_id)
@related_jobs ||= includes(:cities, :company).where("company_id = #{company_id} and id != #{job_id}").order("id DESC").limit(10)
end
end end
<% set_meta_tags title: "VenJob - 404",
description: "VenJob - 404",
keywords: "VenJob - 404" %>
<header class="page-header">
<h2 class="page-title">Page Not Found</h2>
</header>
<div id="primary" class="content-area container" role="main">
<div class="blog-archive">
<div class="content-none">
<p>It seems we can’t find what you’re looking for</p>
</div>
</div>
</div>
\ No newline at end of file
...@@ -23,7 +23,8 @@ Rails.application.routes.draw do ...@@ -23,7 +23,8 @@ Rails.application.routes.draw do
get '/users/applied-jobs', to: 'users#apply_jobs' get '/users/applied-jobs', to: 'users#apply_jobs'
get '/users/favorite-jobs', to: 'users#favorite_jobs' get '/users/favorite-jobs', to: 'users#favorite_jobs'
get '/admins/applies', to: 'admins#applies', as: 'admins_applies' get '/admins/applies', to: 'admins#applies', as: 'admins_applies'
get '/pages/404', to: 'pages#page_404', as: 'page_404'
post '/apply_or_favorite', to: 'users#apply_or_favorite_jobs' post '/apply_or_favorite', to: 'users#apply_or_favorite_jobs'
delete '/remove_favorite_job', to: 'users#remove_favorite_job' delete '/remove_favorite_job', to: 'users#remove_favorite_job'
......
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