4bbd93ded1
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)
50 lines
1001 B
Ruby
50 lines
1001 B
Ruby
# frozen_string_literal: true
|
|
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
|