Commit 13964180 by Quang Vinh Nguyen

fix job apply controller

parent 0aa0df6d
......@@ -24,36 +24,37 @@ class EntriesController < ApplicationController
# POST /entries.json
def create
@entry = Entry.new(entry_params)
render :new and return unless @entry.valid?
@job = Job.find(params[:job_id])
@job = Job.find(params[:job_id])
@user = User.find_by(email: params[:entry][:entry_email])
unless @user
random_password = Devise.friendly_token
@user = User.new(name: params[:entry][:entry_name],
email: params[:entry][:entry_email],
phone: params[:entry][:entry_phone],
address: params[:entry][:entry_address],
password: random_password,
password_confirmation: random_password)
@user.skip_confirmation!
@user.save!
end
@user = User.find_by(email: params[:entry][:entry_email])
unless @user
random_password = Devise.friendly_token
@user = User.new(name: params[:entry][:entry_name],
email: params[:entry][:entry_email],
phone: params[:entry][:entry_phone],
address: params[:entry][:entry_address],
password: random_password,
password_confirmation: random_password)
render :new and return unless @user.valid?
@user.skip_confirmation!
@user.save
end
@entry.user_id = @user.id
@entry.job_id = @job.id
@entry.user_id = @user.id
@entry.job_id = @job.id
if @user.jobs.find_by(id: @job.id)
redirect_to job_url(@job), flash: { secondary: 'You has been entry this job.' }
else
if @entry.save
UserMailer.job_apply(@user, @job).deliver_now
redirect_to @entry, flash: { secondary: 'Thank you for apply. Please check your email.' }
if @user.jobs.find_by(id: @job.id)
redirect_to job_url(@job), flash: { secondary: 'You has been entry this job.' }
else
render :new
if @entry.save
UserMailer.job_apply(@user, @job).deliver_now
redirect_to @entry, flash: { secondary: 'Thank you for apply. Please check your email.' }
else
render :new
end
end
end
end
# PATCH/PUT /entries/1
......
<% provide(:button_text, 'Apply') %>
<% @job = Job.find(params[:job_id]) %>
<h3>Id: <%= @job.id %> -- Job_title: <%= @job.title %> </h3>
<h3>Job_title: <%= @job.title %> </h3>
<% provide(:job_id, @job.id) %>
<%= render 'form', entry: @entry %>
\ No newline at end of file
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