created ID 8-9

parent c4b23a2b
Pipeline #1054 failed with stages
in 0 seconds
......@@ -27,9 +27,9 @@ class FavoriteJobsController < ApplicationController
page_number = @count / Job::LIMIT_PAGE
link_url = request.referer.to_s.split("=")
return redirect_to link_url[0] + "=" + page_number.to_s if count_on_page == 0 && link_url[1].to_i == page_number + 1
return redirect_to link_url[0] + "=" + page_number.to_s if count_on_page == Job::DIVISIBLE && link_url[1].to_i == page_number + 1
return redirect_to request.referer if count_on_page == 0
return redirect_to request.referer if count_on_page == Job::DIVISIBLE
end
end
......
......@@ -4,26 +4,7 @@ class HistoryJobsController < ApplicationController
def index
@count = current_user.histories.count
@history_jobs = current_user.histories.order_history.page(params[:page]).per(Job::LIMIT_PAGE)
end
def destroy
@job = Job.find_by_id(params[:job_id])
@unfollow = current_user.remove_history!(params[:job_id])
respond_to { |format| format.js }
if request.referer.include?("history")
@count = current_user.histories.count
count_on_page = @count % Job::LIMIT_PAGE
page_number = @count / Job::LIMIT_PAGE
link_url = request.referer.to_s.split("=")
return redirect_to link_url[0] + "=" + page_number.to_s if count_on_page == 0 && link_url[1].to_i == page_number + 1
return redirect_to request.referer if count_on_page == 0
end
@history_jobs = current_user.histories.order_history
end
private
......
......@@ -32,9 +32,11 @@ class JobsController < ApplicationController
if signed_in?
@user = JobApplied.where(user_id: current_user.id, job_id: params[:id])
history_jobs = current_user.histories.order_history
history_jobs.last.destroy if history_jobs.count >= Job::LIMIT_HISTORY
founded_history = current_user.histories.find_by(job_id: params[:id])
binding.pry
return founded_history.update(job_id: params[:id]) if founded_history.present?
return founded_history.update(updated_at: Time.current.utc) if founded_history.present?
history = current_user.histories.create!(job_id: params[:id])
end
......
......@@ -18,6 +18,8 @@ class Job < ApplicationRecord
has_many :users, through: :histories
LIMIT_PAGE = 20
LIMIT_HISTORY = 20
DIVISIBLE = 0
scope :limit_job, -> { includes(:cities, :company).order(created_at: :desc).limit(5) }
......
......@@ -5,13 +5,13 @@
<div class="favorite-page">
<%= form_tag apply_job_path(job_id: params[:job_id]), method: :get, enforce_utf8: false do %>
<%= render partial: "favorite_jobs/favorite_job", collection: @favorited_jobs %>
<div class="row justify-content-center">
<div class="row justify-content-center apply-btn">
<%= submit_tag 'Apply Job', name: nil, class: 'btn btn-lg btn-danger' %>
</div>
<% end %>
</div>
<%= paginate @favorited_jobs, outer_window: 2, window: 1 %>
<% else %>
<h1 class="let-favorite">Let's Save Job in Your Favorite</h1>
<h1 class="let-favorite">Let's Favorite Job</h1>
<% end %>
</div>
......@@ -11,17 +11,16 @@
<% end %>
</div>
<div class="row">
<div class="introduction col-10">
<div class="introduction col-12">
<%= strip_tags(history_job.job.format_desc) %><br>
<%= link_to 'Read more..', job_detail_path(history_job.job.id) %>
</div>
<div class="col-6">
<%= history_job.job.cities.map(&:name).join(' | ') %>
</div>
<div class="salary col-3">
<div class="salary col-6">
Salary: <%= history_job.job.salary %>
</div>
<%= link_to "Remove", remove_history_job_path(job_id: history_job.job.id), method: :delete, remote: true, class: "btn btn-danger", id: "button-remove" %>
</div>
</div>
</div>
......
$(".job-id-<%= @job.id %>").remove();
$(".count-histories-jobs").html("<%= @count %>");
......@@ -4,7 +4,7 @@
<div class="history-page">
<%= form_tag apply_job_path(job_id: params[:job_id]), method: :get, enforce_utf8: false do %>
<%= render partial: "history_jobs/history_job", collection: @history_jobs %>
<div class="row justify-content-center">
<div class="row justify-content-center apply-btn">
<%= submit_tag 'Apply Job', name: nil, class: 'btn btn-lg btn-danger' %>
</div>
<% end %>
......
......@@ -37,10 +37,9 @@ Rails.application.routes.draw do
delete 'unfavorite_job', to: 'favorite_jobs#destroy', as: :unfavorite_job
get 'favorite', to: 'favorite_jobs#index', as: :favorite_jobs
delete 'remove_history', to: 'history_jobs#destroy', as: :remove_history_job
get 'history', to: 'history_jobs#index', as: :history_jobs
resources :history_jobs, only: [:destroy, :index]
resources :history_jobs, only: [:index]
resources :favorite_jobs, only: [:create, :destroy, :index]
resources :job_applieds,only: [:new, :create]
resources :reset_passwords, only: [:edit, :update]
......
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