Commit 6736961a by Mai Hoang Thai Ha

use session to keep value when back form

parent b51d4466
......@@ -2,14 +2,22 @@ class AppliesController < ApplicationController
before_action :load_job, only: %i[new confirm create]
def new
@apply = current_user.apply_jobs.build
@apply = if request.referer.include?('confirm') && session[:apply_job].present?
ApplyJob.new(session[:apply_job])
else
current_user.apply_jobs.build
end
end
def confirm
@apply = current_user.apply_jobs.build(apply_params)
@apply.job = @job
render 'new' if @apply.invalid?
if @apply.valid?
session[:apply_job] = @apply
else
render 'new'
end
end
def create
......@@ -23,6 +31,7 @@ class AppliesController < ApplicationController
else
render 'new'
end
session[:apply_job] = nil
end
private
......
......@@ -15,4 +15,4 @@ ActiveStorage.start()
import "bootstrap"
window.bootstrap = require("bootstrap");
import "../stylesheets/application.scss";
import "./validation";
......@@ -34,7 +34,7 @@
span.form-control
= url_for(@apply.cv)
= link_to 'Edit', apply_path(job_id: @job.id), class: 'btn btn-secondary w-25 btn-height mr-5 my-5'
= link_to 'Edit', :back, class: 'btn btn-secondary w-25 btn-height mr-5 my-5'
= f.submit 'Confirm', class: 'btn btn-primary w-25 btn-height mx-5 my-5'
......
......@@ -14,13 +14,13 @@
.col-2
= f.label :user_name, 'Full name', class: 'form-label label'
.col-10
= f.text_field :user_name, value: @current_user.name, class: 'form-control'
= f.text_field :user_name, value: @apply.user_name ||= @current_user.name, class: 'form-control'
span.form-msg
.row.mb-5.form-group
.col-2
= f.label :email, class: 'form-label label'
.col-10
= f.text_field :email, value: @current_user.email, class: 'form-control'
= f.text_field :email, value: @apply.email ||= @current_user.email, class: 'form-control'
span.form-msg
.row.mb-5
/ - if @user.cv.attached?
......@@ -31,8 +31,7 @@
= f.file_field :cv, accept: ApplyJob::ACCEPT_CONTENT_TYPE, class: 'form-control'
= f.submit 'Confirm', class: 'btn btn-primary w-25 my-4 btn-height'
/ = render 'validate_form'
= javascript_pack_tag 'validation'
= render 'validate_form'
javascript:
Validator({
form: '#apply-form',
......
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