fix reviews

parent 294232a1
Pipeline #1421 canceled with stages
in 0 seconds
class FavoriteJobsController < ApplicationController class FavoriteJobsController < ApplicationController
include ApplicationHelper include ApplicationHelper
before_action :check_params_job, only: %i[update destroy]
def index def index
@favorites = favorite_query.order_favorite(current_user).page(params[:page]) @favorites = favorite_query.order_favorite(current_user).page(params[:page])
end end
def update def update
job = Job.find_by(id: params[:job_id]) or not_found
favorite = favorite_query.find_favorite(job_params, current_user) favorite = favorite_query.find_favorite(job_params, current_user)
if favorite.nil? if favorite.nil?
FavoriteJob.create(job: job, user: current_user) FavoriteJob.create(job: @job, user: current_user)
@favorite_exists = true @favorite_exists = true
else else
favorite.destroy favorite.destroy
@favorite_exists = false @favorite_exists = false
end end
respond_to do |format| respond_to do |format|
format.html { redirect_to new_user_session_path, alert: 'Please sign in.' } format.html { redirect_to new_user_session_path, alert: 'You need to sign in or sign up before continuing.' }
format.js {} format.js {}
end end
end end
...@@ -36,4 +36,8 @@ class FavoriteJobsController < ApplicationController ...@@ -36,4 +36,8 @@ class FavoriteJobsController < ApplicationController
def favorite_query def favorite_query
@favorite_query ||= FavoriteQuery.new @favorite_query ||= FavoriteQuery.new
end end
def check_params_job
@job = Job.find_by(id: params[:job_id]) or not_found
end
end end
...@@ -30,7 +30,7 @@ class JobsController < ApplicationController ...@@ -30,7 +30,7 @@ class JobsController < ApplicationController
else else
history.touch(:updated_at) history.touch(:updated_at)
end end
HistoryJob.first.destroy if HistoryJob.count > 20 HistoryJob.first.destroy if HistoryJob.count > HistoryJob::LIMIT_HISTORY
end end
def job_params def job_params
......
...@@ -26,6 +26,6 @@ module ApplicationHelper ...@@ -26,6 +26,6 @@ module ApplicationHelper
end end
def favorite_text def favorite_text
return @favorite_exists ? 'Unfavorite' : 'Favorite' @favorite_exists ? 'Unfavorite' : 'Favorite'
end end
end end
class HistoryJob < ApplicationRecord class HistoryJob < ApplicationRecord
belongs_to :user belongs_to :user
belongs_to :job belongs_to :job
LIMIT_HISTORY = 20
end end
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
h3.p-3.text-center h3.p-3.text-center
| Favorite Jobs | Favorite Jobs
.col-6.offset-md-5.text-center .d-flex.justify-content-center
= paginate @favorites, window: 1 = paginate @favorites, window: 1
= form_with(url: apply_path, method: :get) do |f| = form_with(url: apply_path, method: :get) do |f|
- @favorites.each do |favorite| - @favorites.each do |favorite|
.row.bg-white .row.bg-white
.col-1.p-3.border.card-body.text-dark.text-center .col-1.p-3.card-body.text-dark.text-center.align-self-center
= f.radio_button :job_id, favorite.job.id, class: "form-check-input mt-0" = f.radio_button :job_id, favorite.job.id, required: true, class: "form-check-input mt-0"
.col-9.p-3.border.card-body.text-dark .col-9.p-3.align-self-center
h5.mb-1 h5.mb-1
= link_to favorite.job.title, detail_path(favorite.job.slug) = link_to favorite.job.title, detail_path(favorite.job.slug)
p.mb-1 p.mb-1
...@@ -21,12 +21,12 @@ h3.p-3.text-center ...@@ -21,12 +21,12 @@ h3.p-3.text-center
= favorite.job.cities.map(&:name).uniq.join(' | ') = favorite.job.cities.map(&:name).uniq.join(' | ')
p.mb-1 p.mb-1
= truncate(favorite.job.overview, length: 250) = truncate(favorite.job.overview, length: 250)
.col-sm-2.p-3.border.favourite .col-2.p-3.text-center.align-self-center
= link_to "Remove", unfavorite_path(job_id: favorite.job.id), method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-outline-primary" = link_to "Remove", unfavorite_path(job_id: favorite.job.id), method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-outline-primary"
-if @favorites.any? -if @favorites.any?
h6.offset-md-4.p-2 .d-flex.justify-content-center.p-2
= page_entries_info @favorites = page_entries_info @favorites
.col-6.offset-md-5.text-center .d-flex.justify-content-center
= paginate @favorites, window: 1 = paginate @favorites, window: 1
.span.p-3.text-center .span.p-3.text-center
= f.submit "Apply job", class: "btn btn-primary btn-lg" = f.submit "Apply job", class: "btn btn-primary btn-lg"
......
...@@ -5,9 +5,9 @@ h3.p-3.text-center ...@@ -5,9 +5,9 @@ h3.p-3.text-center
= form_with(url: apply_path, method: :get) do |f| = form_with(url: apply_path, method: :get) do |f|
- @histories.each do |history| - @histories.each do |history|
.row.bg-white .row.bg-white
.col-1.p-3.border.card-body.text-dark.text-center .col-1.p-3.card-body.text-dark.text-center.align-self-center
= f.radio_button :job_id, history.job.id, class: "form-check-input mt-0" = f.radio_button :job_id, history.job.id, required: true, class: "form-check-input mt-0"
.col-11.p-3.border.card-body.text-dark .col-11.p-3.align-self-center
h5.mb-1 h5.mb-1
= link_to history.job.title, detail_path(history.job.slug) = link_to history.job.title, detail_path(history.job.slug)
p.mb-1 p.mb-1
......
...@@ -28,11 +28,11 @@ ...@@ -28,11 +28,11 @@
p.mb-1 p.mb-1
= truncate(job.overview, length: 250) = truncate(job.overview, length: 250)
.col-sm-2.p-3.favourite .col-sm-2.p-3.favourite
-unless current_user.favorite_jobs.exists?(job.id) -if user_signed_in?
= link_to favorite_text, favorite_update_path(job_id: job.id), id: 'favorite_link', remote: true, class: "btn btn-outline-primary btn-lg" = link_to favorite_text, favorite_update_path(job_id: job.id), id: 'favorite_link', remote: true, class: "btn btn-outline-primary btn-lg"
-else -else
= link_to favorite_text, favorite_update_path(job_id: job.id), class: "btn btn-outline-primary btn-lg" = link_to favorite_text, favorite_update_path(job_id: job.id), class: "btn btn-outline-primary btn-lg"
h6.offset-md-4.px-5 h6.offset-md-4.px
= page_entries_info @jobs = page_entries_info @jobs
h6.offset-md-4 h6.offset-md-4
= paginate @jobs, window: 1 = paginate @jobs, window: 1
\ No newline at end of file
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