Commit 0f84c9fd by Mai Hoang Thai Ha

add index for favorite and history

parent a59c56fc
......@@ -3,7 +3,8 @@ class FavoriteJobsController < ApplicationController
before_action :load_job, only: %i[create destroy]
def index
@apply_jobs = Job.apply_jobs_of(current_user.id).sort_by_date(page: params[:page], per_page: Job::JOB_PER_PAGE)
@jobs = Job.jobs_of('favorite_jobs', current_user.id)
.page(params[:page]).per(Job::JOB_PER_PAGE)
end
def create
......
......@@ -4,6 +4,7 @@ class HistoryJobsController < ApplicationController
def index
# job_id_list = current_user.history_jobs.map(&:job_id)
# @jobs = Job.includes(:cities, :cities_jobs, :company).references(:cities).find(job_id_list)
@history_jobs = Job.history_jobs_of(current_user.id)
@history_jobs = Job.jobs_of('history_jobs', current_user.id)
.page(params[:page]).per(Job::JOB_PER_PAGE)
end
end
......@@ -8,6 +8,6 @@ class HistoryJob < ApplicationRecord
def history_count
history_list = user.history_jobs.order(updated_at: :desc)
history_list.last.destroy if history_list.count > 20
history_list.last.destroy if history_list.count >= 20
end
end
class Job < ApplicationRecord
scope :history_jobs_of, ->(user_id) do
joins(:history_jobs)
.where("history_jobs.user_id = #{user_id}")
scope :jobs_of, ->(model, user_id) do
joins(model.to_sym)
.where("#{model.to_sym}.user_id = #{user_id}")
.includes(:cities, :cities_jobs, :company).references(:cities)
end
......
- provide(:title, 'Job list page')
/ search box
= render 'shared/search'
- provide(:title, 'favorite page')
.container
h1.mt-5
= @name
hr.my-4
.no-padding.d-flex.align-items-center.flex-column
.page-info.p-2
= page_entries_info @apply_jobs
= page_entries_info @jobs
.page-info.p-2
= paginate @apply_jobs
= paginate @jobs
.container
.container
- @apply_jobs.each do |job|
- @jobs.each do |job|
/ job
.job-item
.job-head.d-flex.align-items-center.justify-content-between
......@@ -32,6 +27,6 @@
hr.my-4
.no-padding.d-flex.align-items-center.flex-column
.page-info.p-2
= page_entries_info @apply_jobs
= page_entries_info @jobs
.page-info.p-2
= paginate @apply_jobs
\ No newline at end of file
= paginate @jobs
\ No newline at end of file
- provide(:title, 'favorite page')
.container
.my-5
.no-padding.d-flex.align-items-center.flex-column
.page-info.p-2
= page_entries_info @history_jobs
.page-info.p-2
= paginate @history_jobs
.container
.container
- @history_jobs.each do |job|
/ job
.job-item
.job-head.d-flex.align-items-center.justify-content-between
= link_to job.title, job, class: 'job-title fs-3 text-decoration-none text-reset'
......@@ -18,3 +25,8 @@
.job-desc
= truncate(simple_format(job.description), escape: false, length: 250)
hr.my-4
.no-padding.d-flex.align-items-center.flex-column
.page-info.p-2
= page_entries_info @history_jobs
.page-info.p-2
= paginate @history_jobs
\ No newline at end of file
......@@ -8,6 +8,8 @@ header.navbar.navbar-fixed-top.navbar-inverse
li
= link_to "History", history_jobs_path
li
= link_to "Favorite", favorite_jobs_path
li
= link_to "Profile", user_profile_path
li
= link_to "Log out", destroy_user_session_path, method: :delete
......
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