Commit 29e6862c by Hoang Nam Nguyen

merge history_page

parents bc985c5e 30dad39a
class AppliesController < ApplicationController class AppliesController < ApplicationController
before_action :set_job_id, only: :new
before_action :redirect_to_root, unless: :logged_in?, only: :create 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
@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 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
...@@ -34,6 +38,10 @@ class AppliesController < ApplicationController ...@@ -34,6 +38,10 @@ class AppliesController < ApplicationController
redirect_to root_path redirect_to root_path
end 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,5 +10,9 @@ class JobController < ApplicationController ...@@ -10,5 +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.touch(:updated_at)
end
end end
end end
...@@ -15,7 +15,12 @@ class TopPagesController < ApplicationController ...@@ -15,7 +15,12 @@ class TopPagesController < ApplicationController
@cities = City.limit(ENV["Number_top_page"]) @cities = City.limit(ENV["Number_top_page"])
end end
def show def history
@user = current_user
@job = @user.histories.latest_histories(ENV["NUMBER_HISTORY_PAGE"])
end
def favorite_job
end end
def index def index
......
class History < ApplicationRecord
belongs_to :user
belongs_to :job
scope :latest_histories, ->(num) { order(id: :desc).limit(num)}
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)
......
<div class="row mt-3">
<!--set field password -->
<div class="col-md-2 mb-5">
<strong><i class="text-danger"><%= f.label :name, "Full Name", class: 'form-label' %></i></strong>
</div>
<!--set field password -->
<div class="col-md-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
<%= f.text_field :name, class: 'form-control' %>
</div>
</div>
<!--end set field password -->
<!--set field email -->
<div class="col-md-2">
<strong><i class="text-danger"><%= f.label :email %></i></strong>
</div>
<!--set field email -->
<div class="col-md-10">
<div class="input-group">
<span class="input-group-addon mb-5"><i class="fa fa-envelope" aria-hidden="true"></i></span>
<%= f.email_field :email, class: 'form-control mb-5' %>
</div>
</div>
<!--end field email -->
<div class="col-md-2">
<strong><i class="text-danger">My CV</i></strong>
</div>
<% if current_user.cv? %>
<div class="col-md-10 mb-5 text-center">
<%= link_to 'Download cv',downloadcv_path(id: @current_user.id) %>
</div>
<% else %>
<div class ="col-md-10 mb-5">
<%= link_to 'Upload here',edit_account_activation_path(id: @current_user.id) %>
</div>
<% end %>
<!--end set field all -->
<div class="col-sm-2"></div>
<div class="col-sm-10">
<%= button_tag(type: "submit", class: "btn btn-danger btn-block") do %>
<i class="fa fa-check 4px"></i> Confirm
<% end %>
</div>
</div>
<!--end set button -->
\ No newline at end of file
...@@ -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,59 +15,16 @@ ...@@ -15,59 +15,16 @@
</div> </div>
<h1 class="text-center text-danger">Apply Form</h1> <h1 class="text-center text-danger">Apply Form</h1>
<div class="row ml-5 mt-5"> <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="col-md-10 col-md-offset-3"> <div class="col-md-10 col-md-offset-3">
<!--set message errors -->
<!--end set -->
<!--set field all -->
<%= form_for(@user_apply, url: new_info_path) do |f| %> <%= form_for(@user_apply, url: new_info_path) do |f| %>
<%= render 'shared/error_user_apply'%> <%= render 'shared/error_user_apply'%>
<div class="row mt-3"> <%= render 'form_apply', f: f %>
<!--set field password -->
<div class="col-md-2 mb-5">
<strong><i class="text-danger"><%= f.label :name, "Full Name", class: 'form-label' %></i></strong>
</div>
<!--set field password -->
<div class="col-md-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
<%= f.text_field :name, class: 'form-control' %>
</div>
</div>
<!--end set field password -->
<!--set field email -->
<div class="col-md-2">
<strong><i class="text-danger"><%= f.label :email %></i></strong>
</div>
<!--set field email -->
<div class="col-md-10">
<div class="input-group">
<span class="input-group-addon mb-5"><i class="fa fa-envelope" aria-hidden="true"></i></span>
<%= f.email_field :email, class: 'form-control mb-5' %>
</div>
</div>
<!--end field email -->
<div class="col-md-2">
<strong><i class="text-danger">My CV</i></strong>
</div>
<% if current_user.cv? %>
<div class="col-md-10 mb-5 text-center">
<%= link_to 'Download cv',downloadcv_path(id: @current_user.id) %>
</div>
<% else %>
<div class ="col-md-10 mb-5">
<%= link_to 'Upload here',edit_account_activation_path(id: @current_user.id) %>
</div>
<% end %>
<!--end set field all -->
<div class="col-sm-2"></div>
<div class="col-sm-10">
<%= button_tag(type: "submit", class: "btn btn-danger btn-block") do %>
<i class="fa fa-check 4px"></i> Confirm
<% end %> <% end %>
</div> </div>
</div> </div>
<!--end set button --> <% end %>
<% end %>
</div>
</div>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<div class="row mb-5"> <div class="row mb-5">
<div class="search_list titlejob col-md-10"> <div class="search_list titlejob col-md-10">
<%= link_to job['job_name'].join(','), job_detail_path(job['job_id']), class: 'search_list_jobs_title' %> <%= link_to job['job_name'].join(','), job_detail_path(job['job_id']), class: 'search_list_jobs_title' %>
<% unless job['short_description'].nil? %> <% if job['short_description'].present? %>
<li class="detail_description"> <li class="detail_description">
<%= truncate job['short_description'].join(',') ,length: 250%> <%= truncate job['short_description'].join(',') ,length: 250%>
<%= link_to 'read more',job_detail_path(job['job_id'])%></li> <%= link_to 'read more',job_detail_path(job['job_id'])%></li>
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<li class="detail_description col-md-5"> <li class="detail_description col-md-5">
<%= job['city_name'].join(',') %> <%= job['city_name'].join(',') %>
</li> </li>
<% unless job['salary'].nil? %> <% if 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">
<%= job['salary'].join(',') %> <%= job['salary'].join(',') %>
</li> </li>
......
...@@ -51,11 +51,19 @@ ...@@ -51,11 +51,19 @@
</li> </li>
<% end %> <% end %>
<% if logged_in? %>
<li> <li>
<%= link_to '#',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' %>
<% if history.job.short_description.present? %>
<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>
<% if history.job.salary.present? %>
<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")%>
<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">
......
require 'sidekiq/web' require 'sidekiq/web'
Rails.application.routes.draw do Rails.application.routes.draw do
get 'password_resets/new' get 'password_resets/new'
get 'password_resets/edit' get 'password_resets/edit'
get 'sessions/new' get 'sessions/new'
get 'users/new' get 'users/new'
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 '/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'
...@@ -31,8 +30,8 @@ Rails.application.routes.draw do ...@@ -31,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'
......
class CreateHistories < ActiveRecord::Migration[5.1]
def change
create_table :histories do |t|
t.integer :job_id
t.timestamps
end
end
end
class AddUserIdToHistory < ActiveRecord::Migration[5.1]
def change
add_column :histories, :user_id, :integer
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20171004020516) do ActiveRecord::Schema.define(version: 20171005062654) do
create_table "add_cv_to_users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| create_table "add_cv_to_users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "cv" t.string "cv"
...@@ -43,6 +43,13 @@ ActiveRecord::Schema.define(version: 20171004020516) do ...@@ -43,6 +43,13 @@ ActiveRecord::Schema.define(version: 20171004020516) do
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end end
create_table "histories", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.integer "job_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
end
create_table "industries", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| create_table "industries", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "industry_name" t.string "industry_name"
t.datetime "created_at", null: false t.datetime "created_at", null: false
......
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
job_id: 1
two:
job_id: 1
require 'test_helper'
class HistoryTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# 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