Commit be5a251e by Hoang Nam Nguyen

'finished history_page'

parent 1d758282
class AppliesController < ApplicationController class AppliesController < ApplicationController
before_action :set_job_id, only: :new
before_action :redirect_to_root, unless: :logged_in?, only: :create
def new def new
@user_apply = Apply.new(session[:apply] || {}) @user_apply = Apply.new(session[:apply] || {})
@apply_job = Job.find_by(id: session[:job_id])
end end
def create def create
return if current_user.nil?
@user_apply = Apply.new(user_apply_job) @user_apply = Apply.new(user_apply_job)
@user_apply.job_id = Job.find(params[:id]).id @user_apply.job = Job.find_by(id: session[:job_id])
@user_apply.user_id = @current_user.id @user_apply.user_id = @current_user.id
if @user_apply.valid? if @user_apply.valid?
session[:apply] = @user_apply.as_json session[:apply] = @user_apply
redirect_to confirm_apply_path redirect_to confirm_apply_path
else else
@apply_job = Job.find_by(id: session[:job_id])
render 'new' render 'new'
end end
end end
def confirm_apply def confirm_apply
@user_apply = Apply.new(session[:apply]) @user_apply = Apply.new(session[:apply])
@apply_job = Job.find_by(id: session[:job_id])
end end
def finish def finish
...@@ -30,6 +34,14 @@ class AppliesController < ApplicationController ...@@ -30,6 +34,14 @@ class AppliesController < ApplicationController
private private
def redirect_to_root
redirect_to root_path
end
def set_job_id
session[:job_id] = params[:job_history_id] || params[:job_id]
end
def user_apply_job def user_apply_job
params.require(:apply).permit(:email, :name) params.require(:apply).permit(:email, :name)
end end
......
...@@ -10,7 +10,9 @@ class JobController < ApplicationController ...@@ -10,7 +10,9 @@ class JobController < ApplicationController
def detail def detail
@job = Job.find(params[:id]) @job = Job.find(params[:id])
if logged_in?
@history = History.find_or_create_by(job_id: @job.id,user_id: current_user.id) @history = History.find_or_create_by(job_id: @job.id,user_id: current_user.id)
@history.touch(:updated_at) @history.touch(:updated_at)
end end
end
end end
...@@ -16,6 +16,11 @@ class TopPagesController < ApplicationController ...@@ -16,6 +16,11 @@ class TopPagesController < ApplicationController
end end
def history def history
@user = current_user
@job = @user.histories.new_list_history(ENV["NUMBER_HISTORY_PAGE"])
end
def favorite_job
end end
def index def index
......
class History < ApplicationRecord class History < ApplicationRecord
belongs_to :user belongs_to :user
has_many :jobs belongs_to :job
scope :new_list_history, ->(num) { order(id: :desc).limit(num)}
end end
...@@ -5,6 +5,7 @@ class Job < ApplicationRecord ...@@ -5,6 +5,7 @@ class Job < ApplicationRecord
has_many :industries, through: :job_industries has_many :industries, through: :job_industries
belongs_to :company belongs_to :company
has_many :applies has_many :applies
has_many :histories
scope :recent, -> (num) { order(id: :desc).limit(num) } scope :recent, -> (num) { order(id: :desc).limit(num) }
end end
class User < ApplicationRecord class User < ApplicationRecord
has_many :applies has_many :applies
has_many :histories
has_secure_password(validations: false) has_secure_password(validations: false)
......
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
<!--set button update --> <!--set button update -->
<div class="row ml-5 pb-5 pl-5"> <div class="row ml-5 pb-5 pl-5">
<div class="col-md-4 text-center "> <div class="col-md-4 text-center ">
<%= link_to form_apply_path(id: @user_apply.job.id),class: 'btn btn-danger' do %> <%= link_to form_apply_path(job_id: @user_apply.job.id),class: 'btn btn-danger' do %>
<i class="fa fa-wrench"></i> Edit <i class="fa fa-wrench"></i> Edit
<% end %> <% end %>
</div> </div>
......
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
</div> </div>
<h1 class="text-center text-danger">Apply Form</h1> <h1 class="text-center text-danger">Apply Form</h1>
<h2 class="text-center"><%= @apply_job.try(:job_title) %></h2>
<% if current_user.applied_job?(@apply_job) %>
<h2 class="text-center text-danger mt-5">You applied this job</h2>
<% else %>
<div class="row ml-5 mt-5"> <div class="row ml-5 mt-5">
<div class="col-md-10 col-md-offset-3"> <div class="col-md-10 col-md-offset-3">
<!--set message errors --> <!--set message errors -->
...@@ -69,5 +73,6 @@ ...@@ -69,5 +73,6 @@
</div> </div>
<!--end set button --> <!--end set button -->
<% end %> <% end %>
<% end %>
</div> </div>
</div> </div>
...@@ -51,11 +51,19 @@ ...@@ -51,11 +51,19 @@
</li> </li>
<% end %> <% end %>
<% if logged_in? %>
<li> <li>
<%= link_to history_path,class: 'btn btn-info distance mt-1 no-gutters' do %> <%= link_to history_path,class: 'btn btn-info distance mt-1 no-gutters' do %>
<i class="fa fa-history"></i> History <i class="fa fa-history"></i> History
<% end %> <% end %>
</li> </li>
<% else %>
<li>
<%= link_to root_path,class: 'btn btn-info distance mt-1 no-gutters' do %>
<i class="fa fa-history"></i> History
<% end %>
</li>
<% end %>
</ul> </ul>
</div> </div>
</div> </div>
......
<div class="container mt-5" >
<div class="row mb-5 ml-5">
<div class="search_list titlejob col-md-10">
<div class="container">
<div class="row">
<div class="col-1 mt-5">
<%= radio_button_tag 'job_history_id', history.job.id %>
</div>
<div class="col-11" >
<%= link_to history.job.job_title,job_detail_path(history.job.id),class: 'search_list_jobs_title' %>
<% unless history.job.short_description.nil? %>
<li class="detail_description">
<%= truncate history.job.short_description,length: 250 %>
<%= link_to 'read more',job_detail_path(history.job.id)%></li>
</li>
<% end %>
<div class="row ml-0">
<li class="detail_description col-md-5">
<%= history.job.cities.map(&:location).join(',') %>
</li>
<% unless history.job.salary.nil? %>
<li class=" detail_description float-right text-success col-md-5">
<%= history.job.salary%>
</li>
<% end -%>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<%= provide(:title,"History")%> <%= provide(:title,"History")%>
<h1 class="text-danger text-center mt-5">History</h1> <h1 class="text-danger text-center mt-5">History</h1>
<%= form_tag(form_apply_path, method: :get) do %>
<%= render partial: "history",collection: @job, as: :history %>
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-9">
<%= button_tag(type: "submit", class: "btn btn-danger btn-block") do %>
<i class="fa fa-key 4px"></i> Apply
<% end %>
</div>
</div>
<% end %>
...@@ -6,16 +6,16 @@ ...@@ -6,16 +6,16 @@
</div> </div>
</div> </div>
<%= form_tag job_index_path, method: :get do %> <%= form_tag job_index_path, method: :get do %>
<div class="row search_field mt-3"> <div class="row search_field mt-3">
<%= search_field_tag 's', nil, placeholder: 'Search...', class: 'col-10 form-control'%> <%= search_field_tag 's', nil, placeholder: 'Search...', class: 'col-10 form-control'%>
<%= submit_tag 'Search', class: 'col-1 btn btn-success form-control ml-4'%> <%= submit_tag 'Search', class: 'col-1 btn btn-success form-control ml-4'%>
</div> </div>
<% end %> <% end %>
<% flash.each do |key, value| %> <% flash.each do |key, value| %>
<div class="alert alert-<%= key %>"><%= value %></div> <div class="alert alert-<%= key %>"><%= value %></div>
<% end %> <% end %>
<h1 class="text-success line_job"> Latest Jobs</h1> <h1 class="text-success line_job"> Latest Jobs</h1>
<div class="row"> <div class="row">
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
<div class="search_list titlejob col-md-10"> <div class="search_list titlejob col-md-10">
<%= link_to apply.job.job_title,job_detail_path(apply.job.id),class: 'search_list_jobs_title' %> <%= link_to apply.job.job_title,job_detail_path(apply.job.id),class: 'search_list_jobs_title' %>
<% unless apply.job.short_description.nil? %> <% if apply.job.short_description.present? %>
<%= binding.pry %>
<li class="detail_description"> <li class="detail_description">
<%= truncate apply.job.short_description,length: 250 %> <%= truncate apply.job.short_description,length: 250 %>
<%= link_to 'read more',job_detail_path(apply.job.id)%></li> <%= link_to 'read more',job_detail_path(apply.job.id)%></li>
...@@ -14,7 +15,7 @@ ...@@ -14,7 +15,7 @@
<li class="detail_description col-md-5"> <li class="detail_description col-md-5">
<%= apply.job.cities.map(&:location).join(',') %> <%= apply.job.cities.map(&:location).join(',') %>
</li> </li>
<% unless apply.job.salary.nil? %> <% if apply.job.salary.present? %>
<li class=" detail_description float-right text-success col-md-5"> <li class=" detail_description float-right text-success col-md-5">
<%= apply.job.salary%> <%= apply.job.salary%>
</li> </li>
......
...@@ -8,6 +8,7 @@ Rails.application.routes.draw do ...@@ -8,6 +8,7 @@ Rails.application.routes.draw do
get '/cities',to: 'top_pages#cities' get '/cities',to: 'top_pages#cities'
get '/industries',to: 'top_pages#industries' get '/industries',to: 'top_pages#industries'
get '/history',to: 'top_pages#history' get '/history',to: 'top_pages#history'
get '/favorite',to: 'top_pages#favorite_job'
get 'top_pages/cities' get 'top_pages/cities'
get 'top_pages/industries' get 'top_pages/industries'
get 'top_pages/top_page' get 'top_pages/top_page'
...@@ -29,8 +30,8 @@ Rails.application.routes.draw do ...@@ -29,8 +30,8 @@ Rails.application.routes.draw do
resources :account_activations, only: [:edit] resources :account_activations, only: [:edit]
resources :password_resets, only: [:new, :create, :edit, :update] resources :password_resets, only: [:new, :create, :edit, :update]
get 'apply/job/:id',controller: :applies,action: :new,as: :form_apply get 'apply',controller: :applies,action: :new,as: :form_apply
post 'apply/job/:id',controller: :applies,action: :create,as: :new_info post 'apply',controller: :applies,action: :create,as: :new_info
get 'apply/confirm', controller: :applies,action: :confirm_apply,as: :confirm_apply get 'apply/confirm', controller: :applies,action: :confirm_apply,as: :confirm_apply
get 'apply/finish',controller: :applies,action: :finish,as: :finish_apply get 'apply/finish',controller: :applies,action: :finish,as: :finish_apply
mount Sidekiq::Web => '/sidekiq' mount Sidekiq::Web => '/sidekiq'
......
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