Commit bcc62012 by Mai Hoang Thai Ha

fixed review, add apply job in favorite/history index, add partials jobs_list_index

parent 1b95b560
// Place all the styles related to the FavoriteJobs controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
// Place all the styles related to the HistoryJobs controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
class AppliesController < ApplicationController
before_action :logged_in_user
before_action :authenticate_user!
before_action :load_job, only: %i[new confirm create]
def index
@jobs = current_user.apply_jobs.eager_load(job: %i[cities cities_jobs company])
.page(params[:page]).per(Job::JOB_PER_PAGE)
end
def new
if use_apply_job_session?
build_params = session[:apply_job]
......@@ -12,7 +17,6 @@ class AppliesController < ApplicationController
def confirm
@apply = current_user.apply_jobs.build(apply_params)
@apply.job = @job
if @apply.valid?
@blob = ActiveStorage::Blob.create_and_upload!(
......@@ -29,7 +33,6 @@ class AppliesController < ApplicationController
def create
@apply = current_user.apply_jobs.build(apply_params)
@apply.job = @job
@apply.cv = ActiveStorage::Blob.find(session[:blob_id])
if @apply.save
......
......@@ -3,8 +3,8 @@ class FavoriteJobsController < ApplicationController
before_action :load_job, only: %i[create destroy]
def index
@jobs = Job.jobs_of('favorite_jobs', current_user.id)
.page(params[:page]).per(Job::JOB_PER_PAGE)
@favorite_jobs = current_user.favorite_jobs.eager_load(job: %i[cities cities_jobs company])
.page(params[:page]).per(Job::JOB_PER_PAGE)
end
def create
......
......@@ -2,9 +2,7 @@ class HistoryJobsController < ApplicationController
before_action :logged_in_user
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.jobs_of('history_jobs', current_user.id)
.page(params[:page]).per(Job::JOB_PER_PAGE)
@history_jobs = current_user.history_jobs.eager_load(job: %i[cities cities_jobs company])
.page(params[:page]).per(Job::JOB_PER_PAGE)
end
end
......@@ -2,7 +2,7 @@ class Job < ApplicationRecord
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)
.eager_load(:cities, :cities_jobs, :company)
end
LATEST_JOBS_LIMIT = 5
......
......@@ -7,6 +7,7 @@ class User < ApplicationRecord
has_many :apply_jobs, dependent: :destroy
has_many :favorite_jobs, dependent: :destroy
has_many :history_jobs, dependent: :destroy
has_one_attached :cv
validates :cv, content_type: { in: ACCEPT_CONTENT_TYPE,
......
.job-item
.job-head.d-flex.align-items-center.justify-content-between
= link_to applied_job.job.title, applied_job.job, class: 'job-title fs-3 text-decoration-none text-reset'
- if user_signed_in? && current_user.favorite?(applied_job.job)
= render 'shared/unfavorite', job_id: applied_job.job.id
- else
= render 'shared/favorite', job_id: applied_job.job.id
.job-caption
= link_to applied_job.job.company.name, '#', class: 'job-company text-decoration-none text-secondary'
p.job-salary.text-success
| Salary: #{applied_job.job.salary}
ul.list-unstyled
= show_location(applied_job.job.cities)
.job-desc
= truncate(simple_format(applied_job.job.description), escape: false, length: 250)
.applied-at
strong Applied at:
= applied_job.updated_at.strftime('%d/%m/%Y')
hr.my-4
- provide(:title, 'User Jobs')
.container.py-5
h1.text-center.my-job-label My Job
.no-padding.d-flex.align-items-center.flex-column
.page-info.p-2
= page_entries_info @jobs
.page-info.p-2
= paginate @jobs
= render partial: "my_jobs", collection: @jobs, as: :applied_job
.no-padding.d-flex.align-items-center.flex-column
.page-info.p-2
= page_entries_info @jobs
.page-info.p-2
= paginate @jobs
\ No newline at end of file
- provide(:title, 'favorite page')
.container
.no-padding.d-flex.align-items-center.flex-column
.page-info.p-2
= page_entries_info @jobs
.page-info.p-2
= paginate @jobs
.container
.container
- @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'
- if user_signed_in? && current_user.favorite?(job)
= render 'shared/unfavorite', job_id: job.id
- else
= render 'shared/favorite', job_id: job.id
.job-caption
= link_to job.company.name, '#', class: 'job-company text-decoration-none text-secondary'
p.job-salary.text-success
| Salary: #{job.salary}
ul.list-unstyled
= show_location(job.cities)
.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 @jobs
.page-info.p-2
= paginate @jobs
\ No newline at end of file
- provide(:title, 'History page')
- if @favorite_jobs.empty?
h2 No jobs in your history
- else
= render partial: 'shared/jobs_list_index', object: @favorite_jobs, as: 'jobs'
- provide(:title, 'favorite page')
.container
.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'
- if user_signed_in? && current_user.favorite?(job)
= render 'shared/unfavorite', job_id: job.id
- else
= render 'shared/favorite', job_id: job.id
.job-caption
= link_to job.company.name, '#', class: 'job-company text-decoration-none text-secondary'
p.job-salary.text-success
| Salary: #{job.salary}
ul.list-unstyled
= show_location(job.cities)
.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
- provide(:title, 'History page')
- if @history_jobs.empty?
h2 No jobs in your history
- else
= render partial: 'shared/jobs_list_index', object: @history_jobs, as: 'jobs'
......@@ -6,6 +6,8 @@ header.navbar.navbar-fixed-top.navbar-inverse
ul.nav.navbar-nav.navbar-right.text-light
- if user_signed_in?
li
= link_to "Apply jobs", apply_jobs_path
li
= link_to "History", history_jobs_path
li
= link_to "Favorite", favorite_jobs_path
......
.container.py-5
.no-padding.d-flex.align-items-center.flex-column
.page-info.p-2
= page_entries_info jobs
.page-info.p-2
= paginate jobs
.container
= form_with(url: apply_job_path, method: :get) do |f|
- jobs.each do |item|
.row
.col-1.job-check.align-self-center
= f.radio_button :job_id, item.job.id, class: 'btn-check', id: "option-#{item.job.id}"
= f.label 'Choose', class: 'btn btn-outline-primary', for: "option-#{item.job.id}"
.job-item.col-10
.job-head
= link_to item.job.title, item.job, class: 'job-title fs-3 text-decoration-none text-reset'
.job-caption
= link_to item.job.company.name, '#', class: 'job-company text-decoration-none text-secondary'
p.job-salary.text-success
| Salary: #{item.job.salary}
ul.list-unstyled
= show_location(item.job.cities)
.job-desc
= truncate(simple_format(item.job.description), escape: false, length: 250)
.job-fav.col-1
- if user_signed_in? && current_user.favorite?(item.job)
= render 'shared/unfavorite', job_id: item.job.id
- else
= render 'shared/favorite', job_id: item.job.id
hr.my-4
.d-flex.justify-content-center
= f.submit 'Apply job', class: 'btn btn-primary w-50'
.no-padding.d-flex.align-items-center.flex-column
.page-info.p-2
= page_entries_info jobs
.page-info.p-2
= paginate jobs
\ No newline at end of file
......@@ -79,8 +79,6 @@ javascript:
rules: [
Validator.isRequired('#user_email'),
Validator.isEmail('#user_email'),
Validator.isRequired('#user_name'),
Validator.isRequired('#user_address'),
Validator.isRequired('#user_phone')
Validator.isRequired('#user_name')
]
})
\ No newline at end of file
......@@ -22,6 +22,7 @@ Rails.application.routes.draw do
get '/jobs/:model/:slug', to: 'jobs#index', as: :job_list
get '/my', to: 'users#show', as: :user_profile
get '/my/jobs', to: 'applies#index', as: :apply_jobs
get '/apply', to: 'applies#new', as: :apply_job
post '/confirm', to: 'applies#confirm', as: :confirm_job
post '/done', to: 'applies#create', as: :done_job
......
class RemoveIndexFormFavorite < ActiveRecord::Migration[6.1]
def change
remove_index :favorite_jobs, name: :index_favorite_jobs_on_job_id_and_job_id
end
end
class AddNewIndexToFavorite < ActiveRecord::Migration[6.1]
def change
add_index :favorite_jobs, %i[job_id user_id], unique: true
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_09_01_065858) do
ActiveRecord::Schema.define(version: 2021_09_07_064156) do
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name", null: false
......@@ -80,8 +80,8 @@ ActiveRecord::Schema.define(version: 2021_09_01_065858) do
t.bigint "user_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["job_id", "user_id"], name: "index_favorite_jobs_on_job_id_and_user_id", unique: true
t.index ["job_id"], name: "index_favorite_jobs_on_job_id"
t.index ["job_id"], name: "index_favorite_jobs_on_job_id_and_job_id", unique: true
t.index ["user_id"], name: "index_favorite_jobs_on_user_id"
end
......
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