Creating upload file

parent d247142d
Pipeline #1009 failed with stages
in 0 seconds
...@@ -29,3 +29,4 @@ ...@@ -29,3 +29,4 @@
# Ignore master key for decrypting credentials and more. # Ignore master key for decrypting credentials and more.
/config/master.key /config/master.key
/config/local_env.yml
class JobAppliedsController < ApplicationController class JobAppliedsController < ApplicationController
before_action :sign_in_validation, only: [:new] before_action :sign_in_validation, only: [:new, :confirmation, :create]
before_action :find_job_id, only: [:new]
def new def new
end end
def confirmation def confirmation
binding.pry @user = current_user.job_applieds.new(apply_params)
@user = JobApplied.new(apply_params) @cv_name = @user.cv_user.cache_name
if @user.invalid?
@user.errors.full_messages.each do |message|
flash[:danger] = message
redirect_to apply_job_path(job_id: apply_params[:job_id])
end
end
end end
def create def create
binding.pry @user = current_user.job_applieds.new(apply_params)
@user = JobApplied.new(apply_params) return redirect_to apply_job_path(job_id: apply_params[:job_id]) unless @user.save
@user.update_attributes(:cv_user, apply_params[:cv_user])
end end
private private
...@@ -24,4 +33,8 @@ class JobAppliedsController < ApplicationController ...@@ -24,4 +33,8 @@ class JobAppliedsController < ApplicationController
def apply_params def apply_params
params.require(:job_applied).permit(:name, :email, :job_id, :cv_user) params.require(:job_applied).permit(:name, :email, :job_id, :cv_user)
end end
def find_job_id
return redirect_to jobs_path unless Job.find_by(id: params[:job_id])
end
end end
...@@ -7,6 +7,6 @@ class JobApplied < ApplicationRecord ...@@ -7,6 +7,6 @@ class JobApplied < ApplicationRecord
validates :name, presence: true, length: { maximum: 200 } validates :name, presence: true, length: { maximum: 200 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(?:\.[a-z\d\-]+)*\.[a-z]+\z/i VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(?:\.[a-z\d\-]+)*\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, validates :email, presence: true, length: { maximum: 200 }, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false } uniqueness: { case_sensitive: false }
end end
...@@ -29,14 +29,20 @@ ...@@ -29,14 +29,20 @@
<%= f.label :cv_user, 'CV Upload' %> <%= f.label :cv_user, 'CV Upload' %>
</div> </div>
<div class="col-8-sm"> <div class="col-8-sm">
<%= link_to_if @user.cv_user.present? ,@user.cv_user.identifier, @user.cv_user.url, download: @user.cv_user.identifier do %> <% if @user.cv_user.blank? %>
<%= link_to current_user.cv_user.identifier, current_user.cv_user.url, download: current_user.cv_user.identifier %>
<%= f.hidden_field :cv_user, value: current_user.cv_user.identifier %>
<% elsif @user.cv_user.present? %>
<%= link_to @user.cv_user.identifier, @user.cv_user.url, download: @user.cv_user.identifier %>
<%= f.hidden_field :cv_user, value: @user.cv_user.identifier %>
<% else %>
<div class="cv-none"> <div class="cv-none">
CV hasn't found in your Profile. Upload now! CV hasn't found in your Profile. Upload now!
</div> </div>
<% end %> <% end %>
</div> </div>
</div> </div>
<%= f.hidden_field :job_id, value: params[:job_id] %> <%= f.hidden_field :job_id, value: params[:job_applied][:job_id] %>
<%= link_to 'Edit', apply_job_path(job_id: params[:job_applied][:job_id]), class: 'btn btn-outline-primary btn-lg update-btn' %> <%= link_to 'Edit', apply_job_path(job_id: params[:job_applied][:job_id]), class: 'btn btn-outline-primary btn-lg update-btn' %>
<%= f.submit 'Done', class: 'btn btn-outline-primary btn-lg update-btn' %> <%= f.submit 'Done', class: 'btn btn-outline-primary btn-lg update-btn' %>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<%= render partial: 'ribbon_step', locals: { step1: 'active', step2: '', step3: '' } %> <%= render partial: 'ribbon_step', locals: { step1: 'active', step2: '', step3: '' } %>
</div> </div>
<h1 class="text-center my-page-label">Apply Form</h1> <h1 class="text-center my-page-label">Apply Form</h1>
<%= render 'layouts/flash' %>
<div class="form-login"> <div class="form-login">
<div class="row form d-flex justify-content-center"> <div class="row form d-flex justify-content-center">
<%= form_for(:job_applied, url: confirm_job_path) do |f| %> <%= form_for(:job_applied, url: confirm_job_path) do |f| %>
...@@ -27,7 +28,12 @@ ...@@ -27,7 +28,12 @@
<%= f.label :cv_user, 'My CV' %> <%= f.label :cv_user, 'My CV' %>
</div> </div>
<div class="col-8-sm"> <div class="col-8-sm">
<%= link_to_if current_user.cv_user.present? ,current_user.cv_user.identifier, current_user.cv_user.url, download: current_user.cv_user.identifier do %> <% if current_user.cv_user.present? %>
<%= link_to current_user.cv_user.identifier, current_user.cv_user.url, download: current_user.cv_user.identifier %>
<div class="cv-none">
<%= f.file_field :cv_user, accept: '.doc, .pdf, .xls, .xlsx, .zip',class: 'input-cv' %>
</div>
<% else %>
<div class="cv-none"> <div class="cv-none">
<%= f.file_field :cv_user, accept: '.doc, .pdf, .xls, .xlsx, .zip',class: 'input-cv' %> <%= f.file_field :cv_user, accept: '.doc, .pdf, .xls, .xlsx, .zip',class: 'input-cv' %>
</div> </div>
......
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