Commit a60f35d4 by Quang Vinh Nguyen

fix rubocop entries controller

parent 13964180
...@@ -24,37 +24,37 @@ class EntriesController < ApplicationController ...@@ -24,37 +24,37 @@ class EntriesController < ApplicationController
# POST /entries.json # POST /entries.json
def create def create
@entry = Entry.new(entry_params) @entry = Entry.new(entry_params)
render :new and return unless @entry.valid? render(:new) && 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]) @user = User.find_by(email: params[:entry][:entry_email])
unless @user unless @user
random_password = Devise.friendly_token random_password = Devise.friendly_token
@user = User.new(name: params[:entry][:entry_name], @user = User.new(name: params[:entry][:entry_name],
email: params[:entry][:entry_email], email: params[:entry][:entry_email],
phone: params[:entry][:entry_phone], phone: params[:entry][:entry_phone],
address: params[:entry][:entry_address], address: params[:entry][:entry_address],
password: random_password, password: random_password,
password_confirmation: random_password) password_confirmation: random_password)
render :new and return unless @user.valid? render(:new) && return unless @user.valid?
@user.skip_confirmation! @user.skip_confirmation!
@user.save @user.save
end end
@entry.user_id = @user.id @entry.user_id = @user.id
@entry.job_id = @job.id @entry.job_id = @job.id
if @user.jobs.find_by(id: @job.id) if @user.jobs.find_by(id: @job.id)
redirect_to job_url(@job), flash: { secondary: 'You has been entry this job.' } 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.' }
else else
if @entry.save render :new
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
end end
# PATCH/PUT /entries/1 # PATCH/PUT /entries/1
......
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