skill-assessment-app/app/controllers/admin/quiz_controller.rb
2016-08-22 16:26:21 -05:00

49 lines
971 B
Ruby

module Admin
class QuizController < AdminController
def index
@quizzes = Quiz.all
end
def new
@quiz = Quiz.new
end
def create
@quiz = Quiz.create(quiz_params)
if @quiz.persisted?
redirect_to admin_quizzes_path, flash: { notice: "Sucessfully created quiz" }
else
flash[:error] = "Failed to save quiz."
render :new
end
end
def view
@quiz = Quiz.find(params[:quiz_id])
end
def edit
@quiz = Quiz.find(params[:quiz_id])
end
def update
@quiz = Quiz.find(params[:quiz_id])
if @quiz.update_attributes(quiz_params)
redirect_to admin_quiz_path(@quiz.to_i),
flash: { notice: "Sucessfully updated quiz" }
else
flash[:error] = "Failed to update quiz."
render :edit
end
end
private
def quiz_params
params.require(:quiz).permit(:name, :dept, :unit)
end
end
end