created ID 8-9

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