admin questions work

This commit is contained in:
Mark Moser
2016-08-19 16:02:18 -05:00
parent 63701c8247
commit 6bbbaf4580
27 changed files with 349 additions and 51 deletions

View File

@ -1,21 +1,52 @@
module Admin
class QuestionController < AdminController
def index
@questions = Question.includes(:quiz).order("quizzes.name", { active: :desc }, :sort)
end
def new
@question = Question.new(active: true)
@quizzes = Quiz.all
end
def create
@quizzes = Quiz.all
@question = Question.create(question_params)
if @question.persisted?
redirect_to admin_questions_path, flash: { notice: "Sucessfully created question" }
else
flash[:error] = "Failed to save question."
render :new
end
end
def view
@question = Question.includes(:quiz).find(params[:question_id])
end
def edit
@quizzes = Quiz.all
@question = Question.includes(:quiz).find(params[:question_id])
end
def update
@quizzes = Quiz.all
@question = Question.find(params[:question_id])
if @question.update_attributes(question_params)
redirect_to admin_question_path(@question.to_i),
flash: { notice: "Sucessfully updated question" }
else
flash[:error] = "Failed to update question."
render :edit
end
end
private
def question_params
params.require(:question).permit(:quiz_id, :question, :category, :input_type, :input_options, :sort)
end
end
end