class CandidatesController < ApplicationController
	before_action :authenticate_user!
	def index
		@candidates = Candidate.all
		render "candidates/index.html.erb"
	end

	def edit
		@candidate = Candidate.find(params[:id])		
		render "candidates/edit.html.erb"
	end

	def update
		@candidate = Candidate.find(params[:id])

		if @candidate.update(candidate_params())
			redirect_to candidate_path(@candidate.id)
		else
			render "candidates/edit.html.erb"
		end
	end
	
	def new
		@candidate = Candidate.new
		render "candidates/new.html.erb"
	end

	def create
		@candidate = Candidate.new(candidate_params())

		if @candidate.save
			redirect_to candidate_path(@candidate.id)
		else
			render "candidates/new.html.erb"
		end
	end

	def show
		@candidate = Candidate.find(params[:id])
		render "candidates/show.html.erb"
	end

	def destroy
		@candidate = Candidate.find(params[:id])
		@candidate.destroy!
		redirect_to candidates_path
	end

	def candidate_params
		params.require(:candidate).permit!
	end
end