creating apply job

parent cd52cbde
Pipeline #1015 failed with stages
in 0 seconds
...@@ -7,7 +7,7 @@ class JobAppliedsController < ApplicationController ...@@ -7,7 +7,7 @@ class JobAppliedsController < ApplicationController
def confirmation def confirmation
@user = current_user.job_applieds.new(apply_params) @user = current_user.job_applieds.new(apply_params)
@cv_name = @user.cv_user.cache_name @user.cv_user = current_user.cv_user if apply_params[:cv_user].blank?
if @user.invalid? if @user.invalid?
@user.errors.full_messages.each do |message| @user.errors.full_messages.each do |message|
flash[:danger] = message flash[:danger] = message
...@@ -18,8 +18,10 @@ class JobAppliedsController < ApplicationController ...@@ -18,8 +18,10 @@ class JobAppliedsController < ApplicationController
def create def create
@user = current_user.job_applieds.new(apply_params) @user = current_user.job_applieds.new(apply_params)
return redirect_to apply_job_path(job_id: apply_params[:job_id]) unless @user.save @user.cv_user.retrieve_from_cache!(apply_params[:cv_user])
@user.update_attributes(:cv_user, apply_params[:cv_user]) # if @user.save
#
# end
end end
private private
...@@ -31,7 +33,7 @@ class JobAppliedsController < ApplicationController ...@@ -31,7 +33,7 @@ class JobAppliedsController < ApplicationController
end end
def apply_params def apply_params
params.require(:job_applied).permit(:name, :email, :job_id, :cv_user) params.require(:job_applied).permit(:name, :email, :cv_user, :job_id)
end end
def find_job_id def find_job_id
......
...@@ -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, length: { maximum: 200 }, format: { with: VALID_EMAIL_REGEX }, validates :email, presence: true, length: { maximum: 200 }, format: { with: VALID_EMAIL_REGEX }
uniqueness: { case_sensitive: false } validates :cv_user, presence: true
end end
...@@ -29,17 +29,8 @@ ...@@ -29,17 +29,8 @@
<%= f.label :cv_user, 'CV Upload' %> <%= f.label :cv_user, 'CV Upload' %>
</div> </div>
<div class="col-8-sm"> <div class="col-8-sm">
<% 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 %> <%= 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 %> <%= f.hidden_field :cv_user, value: @user.cv_user.cache_name %>
<% else %>
<div class="cv-none">
CV hasn't found in your Profile. Upload now!
</div>
<% end %>
</div> </div>
</div> </div>
<%= f.hidden_field :job_id, value: params[:job_applied][:job_id] %> <%= f.hidden_field :job_id, value: params[:job_applied][:job_id] %>
......
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