@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
class RecruiterController < ApplicationController
|
||||
before_action :authorize_recruiter, except: [:login, :auth]
|
||||
before_action :collect_quizzes, except: [:login, :auth]
|
||||
|
||||
def index
|
||||
@candidates = current_recruiter.candidates
|
||||
@ -8,12 +9,10 @@ class RecruiterController < ApplicationController
|
||||
|
||||
def new
|
||||
@candidate = Candidate.new
|
||||
@quizzes = Quiz.order(:name)
|
||||
render :form
|
||||
render :new
|
||||
end
|
||||
|
||||
def create
|
||||
@quizzes = Quiz.order(:name)
|
||||
@candidate = Candidate.create(candidate_params.merge(recruiter_id: current_recruiter.id))
|
||||
|
||||
if @candidate.persisted?
|
||||
@ -22,7 +21,23 @@ class RecruiterController < ApplicationController
|
||||
redirect_to recruiter_path, flash: { success: "Sucessfully created candidate #{@candidate.name}" }
|
||||
else
|
||||
flash[:error] = "Failed to save candidate."
|
||||
render :form
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@candidate = Candidate.find_by(id: params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@candidate = Candidate.find_by(id: params[:id])
|
||||
@candidate.update(candidate_params)
|
||||
|
||||
if @candidate.save
|
||||
redirect_to recruiter_path, flash: { success: "#{@candidate.name} updated!" }
|
||||
else
|
||||
flash[:error] = "Failed to save candidate."
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
@ -58,4 +73,8 @@ class RecruiterController < ApplicationController
|
||||
def candidate_params
|
||||
params.require(:candidate).permit(:name, :email, :experience, :quiz_id)
|
||||
end
|
||||
|
||||
def collect_quizzes
|
||||
@quizzes ||= Quiz.order(:name)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user