fix-store-cv-when-back-to-new

parent 1bf09fb6
Pipeline #1395 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
if session[:apply_job].present?
@apply_job = ApplyJob.new(session[:apply_job])
......@@ -19,17 +18,25 @@ class ApplyJobsController < ApplicationController
def confirm
@apply_job = ApplyJob.new(apply_params)
@apply_job.user_id = User.find_by(id: 1).id
if @apply_job.valid?
@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
else
render :new
return render :confirm
end
render :new
end
def done
......@@ -41,7 +48,7 @@ class ApplyJobsController < ApplicationController
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
......
......@@ -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
......
......@@ -12,9 +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"
br
= @apply_job.cv.filename
br
= f.file_field :cv, required: true, accept: "application/pdf", size: { less_than: 5.megabytes, message:"should be less than 5MB" }
= 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