Commit 6736961a by Mai Hoang Thai Ha

use session to keep value when back form

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