fix favorite funtion

parent 6cebaf88
Pipeline #1423 canceled with stages
in 0 seconds
......@@ -11,6 +11,7 @@ class JobsController < ApplicationController
industry = Industry.find_by(slug: params[:industry_slug])
jobs = industry.jobs
@result = industry.name
end
@total = jobs.count
@jobs = jobs.latest_jobs.page(params[:page])
......@@ -18,7 +19,7 @@ class JobsController < ApplicationController
def show
@job = Job.find_by(slug: params[:job_slug]) or not_found
@favorite_exists = !FavoriteJob.find_by(job: @job, user: current_user).nil?
check_favorite_exists(@job)
end
private
......
......@@ -28,4 +28,8 @@ module ApplicationHelper
def favorite_text
@favorite_exists ? 'Unfavorite' : 'Favorite'
end
def check_favorite_exists(input)
@favorite_exists = !FavoriteJob.find_by(job: input, user: current_user).nil?
end
end
| $('#favorite_link').text("
| $("#favorite-#{@job.id}").text("
= favorite_text
| ");
\ No newline at end of file
......@@ -12,6 +12,7 @@
= paginate @jobs, window: 1
.job-list
- @jobs.each do |job|
= check_favorite_exists(job)
.row.bg-white
.col-10.p-3.card-body.text-dark
h5.mb-1
......@@ -29,7 +30,7 @@
= truncate(job.overview, length: 250)
.col-sm-2.p-3.favourite
-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-#{job.id}", remote: true, class: "btn btn-outline-primary btn-lg"
-else
= link_to favorite_text, favorite_update_path(job_id: job.id), class: "btn btn-outline-primary btn-lg"
h6.offset-md-4.px
......
......@@ -52,6 +52,6 @@
= link_to "Apply this Job", apply_path(job_id: @job.id), class: "btn btn-outline-primary btn-lg"
.col.text-start
-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-#{@job.id}", remote: true, class: "btn btn-outline-primary btn-lg"
-else
= link_to favorite_text, favorite_update_path(job_id: @job.id), class: "btn btn-outline-primary btn-lg"
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