recruiter can edit candidate

completes #82
This commit is contained in:
Mark Moser
2016-09-16 11:36:48 -05:00
parent f17ed8e8b1
commit a51a751524
12 changed files with 160 additions and 81 deletions

View File

@ -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