Commit eb96d09b by Son Do Hong

Merge branch 'feature/job_apply' into 'master'

Feature/job apply

See merge request !11
parents 476404b3 c492ff7d
......@@ -4,6 +4,11 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
def check_user_logged_in?
redirect_to login_path unless user_signed_in?
end
protected
def configure_permitted_parameters
......
class ApplyController < ApplicationController
before_action :check_user_logged_in?
before_action :load_job, only: [:new, :done, :confirm]
def new
@apply = if params[:apply].present?
current_user.applies.new(apply_job_params)
else
current_user.applies.new
end
end
def confirm
@apply = current_user.applies.new(apply_job_params)
end
def done
@apply = current_user.applies.new(apply_job_params)
if @apply.save
flash[:success] = "Your application has been saved successfully!"
else
render :new
end
end
private
def load_job
@job = Job.find_by(id: params[:job_id])
end
def apply_job_params
params.require(:apply)
.permit(:cv_url, :first_name, :last_name, :username, :email)
.merge(job_id: @job.id)
end
end
class ApplyMailer < ApplicationMailer
default from: "noreply@gmail.com"
# def notify(done)
# @apply = done
# mail to: @apply.email, subject: "Thank you for apply with VenJob"
# end
end
class Apply < UserJob
end
class Favorite < UserJob
end
class History < UserJob
end
......@@ -4,6 +4,7 @@ class Job < ApplicationRecord
has_many :industry_jobs
has_many :cities, through: :city_jobs
has_many :industries, through: :industry_jobs
has_many :applies
def self.latest_jobs
@latest ||= order(created_at: :desc).take(Settings.top.job.limit)
......
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable
has_many :user_jobs
has_many :applies
has_many :favorites
has_many :histories
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
VALID_USERNAME_REGEX = /\A[a-zA-Z0-9]+\z/
......
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item <%= content_for(:new_step) %>" aria-current="page">
Apply New
</li>
<li class="breadcrumb-item <%= content_for(:confirm_step) %>">
Apply Confirmation
</li>
<li class="breadcrumb-item <%= content_for(:done_step) %>">
Apply Finish
</li>
</ol>
</nav>
<%= content_for(:confirm_step, "active") %>
<%= render "apply_breadcrumb" %>
<div class="container">
<div class="d-flex justify-content-center ">
<div class="card">
<%= form_for(@apply, url: done_path(@job)) do |f|%>
<div class = "form-group row">
<%= f.label :first_name %>
<div class = "form-control">
<%= @apply.first_name %>
</div>
<%= f.hidden_field :first_name, value: @apply.first_name %>
</div>
<div class = "form-group row">
<%= f.label :last_name %>
<div class = "form-control">
<%= @apply.last_name %>
</div>
<%= f.hidden_field :last_name, value: @apply.last_name %>
</div>
<div class = "form-group row">
<%= f.label :email %>
<div class = "form-control">
<%= @apply.email %>
</div>
<%= f.hidden_field :email, value: @apply.email %>
</div>
<div class = "form-group row">
<%= f.label :CV_URL %>
<div class = "form-control">
<%= @apply.cv_url %>
</div>
<%= f.hidden_field :cv_url, value: @apply.cv_url %>
</div>
</br>
<div class = "form-group">
<div class = "actions">
<%= f.submit "Done", class: "btn btn-primary" %>
<%= link_to "Edit", apply_path(@job, apply: { first_name: @apply.first_name,
last_name: @apply.last_name,
email: @apply.email,
cv_url: @apply.cv_url }), class: "btn float-right btn-primary" %>
</div>
<% end %>
</div>
</div>
</div>
</div>
<%= content_for(:done_step, "active") %>
<%= render "apply_breadcrumb" %>
<h4>Thank you for apply</h4>
</br>
<p><%= link_to "Back to TOP page", root_path %></p>
<%= content_for(:new_step, "active") %>
<%= render "apply_breadcrumb" %>
<div class="container">
<div class="d-flex justify-content-center ">
<div class="card">
<div class="card-header text-center">
<h2>Apply Form</h2>
</div>
<%= form_for(@apply, url: confirm_path(@job)) do |f|%>
<div class = "form-group row">
<%= f.label :first_name %>
</br>
<%= f.text_field :first_name, class: "form-control" %>
</div>
<div class = "form-group row">
<%= f.label :last_name %>
</br>
<%= f.text_field :last_name, class: "form-control" %>
</div>
<div class = "form-group row">
<%= f.label :email %>
</br>
<%= f.email_field :email, class: "form-control" %>
</div>
<div class = "form-group row"">
<%= f.label :CV_URL %>
</br>
<%= f.url_field :cv_url, class: "form-control" %>
</div>
<div class = "actions text-center">
<%= f.submit "Confirm", class: "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
</div>
</br>
......@@ -40,10 +40,15 @@
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
</div>
<div class="field">
<%= f.label :Upload_CV %><br />
<%= f.url_field :cv_url %>
</div>
</br>
<div class="actions text-center">
<%= f.submit "Sign up", class: "btn-primary" %>
<%= f.submit "Sign up", class: "btn btn-primary" %>
</div>
<% end %>
</div>
......
......@@ -49,6 +49,6 @@
<dt class="col-sm-3">Requirement:</dt>
<dd class="col-sm-9"><%= simple_format @job.requirement %></dd>
</dl>
<%= link_to "Apply", apply_path, class: "btn btn-primary" %>
</div>
</div
<div class="row align-items-center">
<div class="col text-center">
<%= job.title %>
<%= link_to "#{job.title}", job_path(job.id) %>
</div>
</div>
</br>
......@@ -21,6 +21,9 @@ Rails.application.routes.draw do
get "jobs/city/:city_id", to: "jobs#index", as: "city_jobs"
get "jobs/industry/:industry_id", to: "jobs#index", as: "industry_jobs"
get "detail/:job_id", to: "jobs#show", as: "job"
get "apply/:job_id", to: "apply#new", as: "apply"
post "confirm/:job_id", to: "apply#confirm", as: "confirm"
post "done/:job_id", to: "apply#done", as: "done"
concern :paginatable do
get "(page/:page)", action: :index, on: :collection, as: ""
......
class AddCvUrlToUserJobs < ActiveRecord::Migration[6.0]
def change
add_column :user_jobs, :cv_url, :text
end
end
class AddUsernameToUserJobs < ActiveRecord::Migration[6.0]
def change
add_column :user_jobs, :username, :string
end
end
class AddFirstNameLastNameToUserJobs < ActiveRecord::Migration[6.0]
def change
add_column :user_jobs, :first_name, :string
add_column :user_jobs, :last_name, :string
end
end
class AddEmailToUserJobs < ActiveRecord::Migration[6.0]
def change
add_column :user_jobs, :email, :string
end
end
class ModifyUser < ActiveRecord::Migration[6.0]
def change
remove_column :users, :password_digest, :string
end
end
class ChangeTypeUserJob < ActiveRecord::Migration[6.0]
def change
rename_column :user_jobs, :job_type, :type
change_column :user_jobs, :type, :string
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_01_06_041448) do
ActiveRecord::Schema.define(version: 2020_01_15_032331) do
create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name"
......@@ -71,12 +71,17 @@ ActiveRecord::Schema.define(version: 2020_01_06_041448) do
create_table "user_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.integer "user_id"
t.integer "job_id"
t.integer "job_type"
t.string "type"
t.datetime "favorited_at"
t.datetime "viewed_at"
t.datetime "applied_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.text "cv_url"
t.string "username"
t.string "first_name"
t.string "last_name"
t.string "email"
t.index ["job_id"], name: "index_user_jobs_on_job_id"
t.index ["user_id", "job_id"], name: "index_user_jobs_on_user_id_and_job_id"
t.index ["user_id"], name: "index_user_jobs_on_user_id"
......@@ -91,7 +96,6 @@ ActiveRecord::Schema.define(version: 2020_01_06_041448) do
t.string "first_name"
t.string "last_name"
t.text "cv_url"
t.string "password_digest"
t.integer "role"
t.string "remember_digest"
t.datetime "activated_at"
......
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