skill-assessment-app/app/controllers/recruiter_controller.rb
Mark Moser 4bbd93ded1 rubocop noise: fixes FrozenStringLiteralComment
Adding the .ruby-verison file triggered previously un-run cops, specifically:

  This cop is designed to help upgrade to Ruby 3.0. It will add the
  comment `# frozen_string_literal: true` to the top of files to enable
  frozen string literals. Frozen string literals will be default in Ruby
  3.0. The comment will be added below a shebang and encoding comment. The
  frozen string literal comment is only valid in Ruby 2.3+.

More info on rubocop [Automatic-Corrections](https://github.com/bbatsov/rubocop/wiki/Automatic-Corrections)
2016-09-08 10:30:13 -05:00

54 lines
1.4 KiB
Ruby

# frozen_string_literal: true
class RecruiterController < ApplicationController
before_action :authorize_recruiter, except: [:login, :auth]
def index
@candidates = current_recruiter.candidates
end
def new
@candidate = Candidate.new
render :form
end
def create
@candidate = Candidate.create(candidate_params.merge(recruiter_id: current_recruiter.id))
if @candidate.persisted?
CandidateMailer.welcome(@candidate).deliver_now
RecruiterMailer.candidate_created(@candidate).deliver_now
redirect_to recruiter_path, flash: { success: "Sucessfully created candidate #{@candidate.name}" }
else
flash[:error] = "Failed to save candidate."
render :form
end
end
def login
redirect_to recruiter_path unless current_recruiter.nil?
end
def auth
recruiter = User.find_by(email: auth_params[:email], role: %w(admin recruiter))
if recruiter && recruiter.authenticate(auth_params[:password])
session[:user] = recruiter.to_i
redirect_to recruiter_path
else
redirect_to recruiter_login_path,
flash: { error: "Sorry, incorrect email or password. Please try again." }
end
end
def logout
reset_session
redirect_to recruiter_login_path
end
private
def candidate_params
params.require(:candidate).permit(:name, :email, :experience, :quiz_id)
end
end