created history

parent 3d8bb894
Pipeline #1051 failed with stages
in 0 seconds
class FavoriteJobsController < ApplicationController
before_action :sign_in_favorite_validation, only: %i[create destroy]
before_action :sign_in_validation, only: [:show]
before_action :sign_in_validation, only: [:index]
def index
@count = current_user.favorite_jobs.count
......
class HistoryJobsController < ApplicationController
before_action :sign_in_favorite_validation, only: [:destroy]
before_action :sign_in_validation, only: [:index]
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
end
private
def sign_in_favorite_validation
return if signed_in?
session[:return_to] = request.referer
flash[:warning] = Settings.user.warning_signin
redirect_to login_path
end
def sign_in_validation
return if signed_in?
store_location
flash[:warning] = Settings.user.warning_signin
redirect_to login_path
end
end
......@@ -29,7 +29,15 @@ class JobsController < ApplicationController
def show
session.delete(:job_applied)
return redirect_to jobs_path unless @job
@user = JobApplied.where(user_id: current_user.id, job_id: params[:id]) if signed_in?
if signed_in?
@user = JobApplied.where(user_id: current_user.id, job_id: params[:id])
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?
history = current_user.histories.create!(job_id: params[:id])
end
end
private
......
......@@ -2,5 +2,5 @@ class FavoriteJob < ApplicationRecord
belongs_to :user
belongs_to :job
scope :order_favorite, -> { order("favorite_jobs.updated_at DESC") }
scope :order_favorite, -> { order(updated_at: :desc) }
end
class History < ApplicationRecord
belongs_to :user
belongs_to :job
scope :order_history, -> { order(updated_at: :desc) }
end
......@@ -32,6 +32,10 @@ class User < ApplicationRecord
favorite_jobs.find_by(job_id: job_id).destroy
end
def remove_history!(job_id)
histories.find_by(job_id: job_id).destroy
end
def self.new_remember_token
SecureRandom.urlsafe_base64
end
......
<div class="container">
<% if @favorited_jobs.count > 0 %>
<h1 class="text-center my-job-label">My Favorite Job (<span class="count-favorite-jobs"><%= @count %></span> jobs)</h1>
<h1 class="text-center my-job-label">Favorite Job (<span class="count-favorite-jobs"><%= @count %></span> jobs)</h1>
<%= paginate @favorited_jobs, outer_window: 2, window: 1 %>
<div class="favorite-page">
<%= form_tag apply_job_path(job_id: params[:job_id]), method: :get, enforce_utf8: false do %>
......
<div class="job-id-<%= history_job.job.id %>">
<div class="border border-dark rounded">
<div class="row">
<div class="radio-btn col-1">
<%= radio_button_tag :job_id, history_job.job.id %>
</div>
<div class="job-details col-10">
<div class="title">
<%= link_to job_detail_path(history_job.job.id) do %><strong>
<%= history_job.job.title %></strong>
<% end %>
</div>
<div class="row">
<div class="introduction col-10">
<%= 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">
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>
</div>
</div>
<br>
$(".job-id-<%= @job.id %>").remove();
$(".count-histories-jobs").html("<%= @count %>");
<div class="container">
<% if @history_jobs.count > 0 %>
<h1 class="text-center my-job-label">History(<span class="count-histories-jobs"><%= @count %></span> jobs)</h1>
<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">
<%= submit_tag 'Apply Job', name: nil, class: 'btn btn-lg btn-danger' %>
</div>
<% end %>
</div>
<% else %>
<h1 class="let-favorite">Your History doesn't have jobs</h1>
<% end %>
</div>
......@@ -12,7 +12,7 @@
<li><%= link_to "Register", register_step1_path, class: "nav-item nav-link" %></li>
<% end %>
<li><%= link_to "Favorite", favorite_jobs_path, class: "nav-item nav-link" %></li>
<li><%= link_to "History", '#', class: "nav-item nav-link" %></li>
<li><%= link_to "History", history_jobs_path, class: "nav-item nav-link" %></li>
</ul>
</nav>
</div>
......
......@@ -37,7 +37,11 @@ Rails.application.routes.draw do
delete 'unfavorite_job', to: 'favorite_jobs#destroy', as: :unfavorite_job
get 'favorite', to: 'favorite_jobs#index', as: :favorite_jobs
resources :favorite_jobs, only: [:create, :destroy, :show]
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 :favorite_jobs, only: [:create, :destroy, :index]
resources :job_applieds,only: [:new, :create]
resources :reset_passwords, only: [:edit, :update]
resources :confirmations, only: [:new]
......
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