Commit bd849737 by Mai Hoang Thai Ha

add form apply confirm done

parent f2c78d06
...@@ -33,6 +33,7 @@ group :development, :test do ...@@ -33,6 +33,7 @@ group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'pry-rails', '~> 0.3.9' gem 'pry-rails', '~> 0.3.9'
# gem 'pry-nav', '~> 0.3.0' # gem 'pry-nav', '~> 0.3.0'
gem 'pry', '~> 0.14.1'
end end
group :development do group :development do
......
...@@ -120,7 +120,7 @@ GEM ...@@ -120,7 +120,7 @@ GEM
mail (2.7.1) mail (2.7.1)
mini_mime (>= 0.1.1) mini_mime (>= 0.1.1)
marcel (1.0.1) marcel (1.0.1)
method_source (0.9.2) method_source (1.0.0)
mime-types (3.3.1) mime-types (3.3.1)
mime-types-data (~> 3.2015) mime-types-data (~> 3.2015)
mime-types-data (3.2021.0704) mime-types-data (3.2021.0704)
...@@ -135,9 +135,9 @@ GEM ...@@ -135,9 +135,9 @@ GEM
parallel (1.20.1) parallel (1.20.1)
parser (3.0.2.0) parser (3.0.2.0)
ast (~> 2.4.1) ast (~> 2.4.1)
pry (0.12.2) pry (0.14.1)
coderay (~> 1.1.0) coderay (~> 1.1)
method_source (~> 0.9.0) method_source (~> 1.0)
pry-rails (0.3.9) pry-rails (0.3.9)
pry (>= 0.10.4) pry (>= 0.10.4)
public_suffix (4.0.6) public_suffix (4.0.6)
...@@ -275,6 +275,7 @@ DEPENDENCIES ...@@ -275,6 +275,7 @@ DEPENDENCIES
listen (~> 3.3) listen (~> 3.3)
mysql2 (~> 0.5) mysql2 (~> 0.5)
nokogiri (~> 1.11, >= 1.11.7) nokogiri (~> 1.11, >= 1.11.7)
pry (~> 0.14.1)
pry-rails (~> 0.3.9) pry-rails (~> 0.3.9)
puma (~> 5.0) puma (~> 5.0)
rack-mini-profiler (~> 2.0) rack-mini-profiler (~> 2.0)
......
...@@ -4,18 +4,29 @@ class AppliesController < ApplicationController ...@@ -4,18 +4,29 @@ class AppliesController < ApplicationController
end end
def create def create
binding.pry
@apply = @job.apply_jobs.build(apply_params)
@apply.user_id = 1
# @apply.cv.attach(params[:apply_job][:cv])
if @apply.save
#afasf
else
render 'new'
end
end end
def show def show
end end
def new def new
# if params[:job_id].present? @apply = @job.apply_jobs.build
# @job = Job.find_by(id: params[:job_id])
# end
end end
def confirm def confirm
@name = params[:apply_job][:user_name]
@email = params[:apply_job][:email]
@cv = params[:apply_job][:cv]
end end
private private
...@@ -23,4 +34,8 @@ class AppliesController < ApplicationController ...@@ -23,4 +34,8 @@ class AppliesController < ApplicationController
def load_job def load_job
@job = Job.find_by(id: params[:job_id]) @job = Job.find_by(id: params[:job_id])
end end
def apply_params
params.require(:apply_job).permit(:user_name, :email, :cv)
end
end end
class ApplyJob < ApplicationRecord class ApplyJob < ApplicationRecord
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
belongs_to :job belongs_to :job
belongs_to :user belongs_to :user
has_one_attached :cv has_one_attached :cv
validates :user_name, presence: true, length: { maximum:50 }
validates :email, presence: true, length: { maximum:255 },
format: {with: VALID_EMAIL_REGEX},
uniqueness: true
# validates :image, content_type
# size: { less_than: 5.megabytes,
# message: "should be less than 5MB" }
end end
- provide(:title, "Apply job") - provide(:title, "Apply job")
.container .container
h1.my-5.text-center h1.my-5.text-center
| Apply for | Confirm
= @job.title
.col .col
= form_with(url: confirm_path, local: true) do |f| = form_with(scope: :apply_job, url: done_path(job_id: @job), local: true) do |f|
.mb-3 .mb-3
= f.label :name, 'Full name', class: 'form-label' = f.label :name, 'Full name:', class: 'form-label'
= f.text_field :name, class: 'form-control' span.mx-2
= @name
= f.hidden_field :user_name, value: @name, class: 'form-control'
.mb-3 .mb-3
= f.label :email, class: 'form-label' = f.label :email, 'Email:', class: 'form-label'
= f.email_field :email, class: 'form-control' span.mx-2
= @email
= f.hidden_field :email, value: @email, class: 'form-control'
span.mb-3.d-block.align-center span.mb-3.d-block.align-center
= f.label :cv, 'Cv:', class: 'form-label'
/ = f.hidden_field :cv, value: @cv
= f.file_field :cv = f.file_field :cv
= f.submit "Submit", class: "btn btn-primary"
span.mx-2
= @cv.original_filename
= link_to 'Edit', apply_path(job_id: @job.id), class: "btn btn-secondary py-2 px-4"
= f.submit "Confirm", class: "btn btn-primary"
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
| Apply for | Apply for
= @job.title = @job.title
.col .col
= form_with(url: confirm_path, local: true) do |f| = form_with(model: @apply, url: confirm_path(job_id: @job), local: true) do |f|
.mb-3 .mb-3
= f.label :name, 'Full name', class: 'form-label' = f.label :user_name, 'Full name', class: 'form-label'
= f.text_field :name, class: 'form-control' = f.text_field :user_name, class: 'form-control'
.mb-3 .mb-3
= f.label :email, class: 'form-label' = f.label :email, class: 'form-label'
= f.email_field :email, class: 'form-control' = f.text_field :email, class: 'form-control'
span.mb-3.d-block.align-center span.mb-3.d-block.align-center
= f.file_field :cv = f.file_field :cv
= f.submit "Submit", class: "btn btn-primary" = f.submit "Submit", class: "btn btn-primary"
...@@ -12,5 +12,5 @@ Rails.application.routes.draw do ...@@ -12,5 +12,5 @@ Rails.application.routes.draw do
get '/apply', to: 'applies#new' get '/apply', to: 'applies#new'
post '/confirm', to: 'applies#confirm' post '/confirm', to: 'applies#confirm'
post '/done', to: 'applies#done' post '/done', to: 'applies#create'
end end
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