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

Add concerns for cookies_history

parent b07006ff
Pipeline #633 failed with stages
in 0 seconds
module CookiesHistory
def set_job_histories
if cookies[:job_ids_history].nil?
cookies[:job_ids_history] = { value: @job.id, expires: Time.now + 3600 }
else
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
\ No newline at end of file
class JobsController < ApplicationController class JobsController < ApplicationController
include CookiesHistory
def index def index
if params[:city_id] if params[:city_id]
@jobs = Job.by_cities(params[:city_id]).page(params[:page]) @jobs = Job.by_cities(params[:city_id]).page(params[:page])
...@@ -23,16 +25,7 @@ class JobsController < ApplicationController ...@@ -23,16 +25,7 @@ class JobsController < ApplicationController
@favorite = Favorite.find_by(job_id: params[:id], user_id: current_user.id) @favorite = Favorite.find_by(job_id: params[:id], user_id: current_user.id)
History.create_history(params[:id], current_user.id) History.create_history(params[:id], current_user.id)
else else
if cookies[:job_ids_history].blank? set_job_histories
cookies[:job_ids_history] = { value: @job.id, expires: Time.now + 3600 }
else
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
@relate_jobs = Job.related_jobs(@job.company_id, @job.id) @relate_jobs = Job.related_jobs(@job.company_id, @job.id)
end 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