skill-assessment-app/app/controllers/admin/quiz_controller.rb

50 lines
1001 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-08-17 17:49:09 -05:00
module Admin
class QuizController < AdminController
def index
2016-08-18 15:35:17 -05:00
@quizzes = Quiz.all
2016-08-17 17:49:09 -05:00
end
def new
2016-08-18 15:35:17 -05:00
@quiz = Quiz.new
2016-08-17 17:49:09 -05:00
end
def create
2016-08-18 15:35:17 -05:00
@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
2016-08-17 17:49:09 -05:00
end
def view
2016-08-18 15:35:17 -05:00
@quiz = Quiz.find(params[:quiz_id])
2016-08-17 17:49:09 -05:00
end
def edit
2016-08-18 15:35:17 -05:00
@quiz = Quiz.find(params[:quiz_id])
2016-08-17 17:49:09 -05:00
end
def update
2016-08-18 15:35:17 -05:00
@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
2016-08-17 17:49:09 -05:00
end
2016-08-18 15:35:17 -05:00
private
def quiz_params
2016-08-18 18:22:57 -05:00
params.require(:quiz).permit(:name, :dept, :unit)
2016-08-18 15:35:17 -05:00
end
2016-08-17 17:49:09 -05:00
end
end