Commit 45fb6219 by Thanh Hung Pham

Merge branch 'store-file-cv' into 'master'

store-file-cv

See merge request !8
parents 8ca02714 bc2c5d35
Pipeline #1396 failed with stages
in 0 seconds
......@@ -7,9 +7,16 @@
padding-top: 10px;
padding-bottom: 10px;
}
body {
position: relative;
padding-bottom: 228px;
min-height: 100vh;
}
footer {
min-height: 227px;
position:absolute;
bottom: 0;
width: 100%;
}
.navbar ul li a {
......
class ApplyJobsController < ApplicationController
include ApplicationHelper
def new
job = Job.find_by(id: params[:job_id])
return root_path unless job
job = Job.find_by(id: params[:job_id]) or not_found
@apply_job = if session[:apply_job].present?
ApplyJob.new(session[:apply_job])
else
ApplyJob.new
end
@apply_job.job_id = job.id
if session[:apply_job].present?
@apply_job = ApplyJob.new(session[:apply_job])
if session[:blob_id].present?
@blob = ActiveStorage::Blob.find(session[:blob_id])
@apply_job.assign_attributes(cv: @blob)
end
else
@apply_job = ApplyJob.new
end
@apply_job.job = job
end
def confirm
@apply_job = ApplyJob.new(apply_params)
@apply_job.user_id = User.find_by(id: 1).id
@apply_job.validate
if @apply_job.cv.attached? && @apply_job.errors[:cv].empty?
@blob = ActiveStorage::Blob.create_and_upload!(
io: apply_params[:cv],
filename: apply_params[:cv].original_filename,
content_type: apply_params[:cv].content_type
)
session[:blob_id] = @blob.id
elsif @apply_job.cv.attached? && !@apply_job.errors[:cv].empty? && session[:blob_id]
ActiveStorage::Blob.find_by(id: session[:blob_id]).try(:destroy)
elsif !@apply_job.cv.attached? && session[:blob_id]
@blob = ActiveStorage::Blob.find_by(id: session[:blob_id])
@apply_job.assign_attributes(cv: @blob)
end
if @apply_job.valid?
session[:apply_job] = @apply_job
render :confirm
else
render :new
return render :confirm
end
render :new
end
def done
@apply_job = ApplyJob.new(apply_params)
@apply_job.user_id = User.find_by(id: 1).id
@job = Job.latest_jobs.find(apply_params[:job_id])
@apply_job.cv = ActiveStorage::Blob.find(session[:blob_id])
if @apply_job.save
ApplyJobMailer.with(apply_job: @apply_job, job: @job).create_apply.deliver_now
flash.now[:success] = 'You have applied successfully'
else
flash.now[:danger] = 'Please apply again'
flash[:danger] = 'Have something wrong. Please apply again'
redirect_to root_url
end
session[:apply_job] = nil
session[:blob_id] = nil
end
private
def apply_params
params.require(:apply_job).permit(:name, :email, :cv, :job_id)
params.require(:apply_job).permit(:name, :email, :cv, :job_id, :id)
end
end
end
\ No newline at end of file
......@@ -14,4 +14,14 @@ module ApplicationHelper
def current_page?(*paths)
paths.include?(request.path)
end
def not_found
raise ActionController::RoutingError.new('Not Found')
rescue
render_404
end
def render_404
render file: "#{Rails.root}/public/404.html", status: :not_found
end
end
......@@ -4,8 +4,8 @@ class Industry < ApplicationRecord
has_and_belongs_to_many :jobs
LATEST_INDUSTRY_NUMBER = 9
scope :top_industries, -> { group(:name, :slug).order('count_all DESC').count.take(LATEST_INDUSTRY_NUMBER) }
scope :industry_list, -> { group(:name, :slug).having('count_all >= ?', 1).order('count_all DESC').count }
scope :top_industries, -> { joins(:jobs).group(:name, :slug).order('count_all DESC').count.take(LATEST_INDUSTRY_NUMBER) }
scope :industry_list, -> { joins(:jobs).group(:name, :slug).having('count_all >= ?', 1).order('count_all DESC').count }
def normalize_friendly_id(string)
string.to_s.to_slug.normalize(transliterations: :vietnamese).to_s
......
......@@ -15,9 +15,10 @@ h2.text-center
placeholder: "Type email...", class: 'form-control'
= f.hidden_field :email
p.my-1
= f.label :cv, "CV"
p
= f.file_field :cv, required: true, accept: "application/pdf", size: { less_than: 5.megabytes, message:"should be less than 5MB" }
= f.label :cv, "Your CV"
br
= f.hidden_field :id, value: @blob.id
= @apply_job.cv.filename
.span.p-3.text-center
= link_to "Back", apply_path(job_id: @apply_job.job_id), class: "btn btn-primary btn-space"
= f.submit "Done", class: "btn btn-primary btn-space"
\ No newline at end of file
......@@ -12,7 +12,8 @@ h2.text-center.form-title
= f.text_field :email, required: true, length: { maximum: 255 }, format: { with: ApplyJob::VALID_EMAIL_REGEX}, placeholder: "Type email...", class: 'form-control'
p.my-1
= f.label :cv, "CV"
p
= f.file_field :cv, required: true, accept: "application/pdf", size: { less_than: 5.megabytes, message:"should be less than 5MB" }
= @apply_job.cv.filename
br
= f.file_field :cv, accept: "application/pdf", size: { less_than: 5.megabytes, message:"should be less than 5MB" }
.span.p-3.text-center
= f.submit "Confirm", class: "btn btn-primary"
\ No newline at end of file
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