From 77684b2c3e0a11a3317d0895217c38ccf00e53b0 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Fri, 19 Aug 2016 16:41:44 -0500 Subject: [PATCH] updated params processing --- app/controllers/admin/question_controller.rb | 18 +++++++++++++++--- app/controllers/quiz_controller.rb | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/question_controller.rb b/app/controllers/admin/question_controller.rb index 33ecdd1..e31c6d2 100644 --- a/app/controllers/admin/question_controller.rb +++ b/app/controllers/admin/question_controller.rb @@ -11,7 +11,7 @@ module Admin def create @quizzes = Quiz.all - @question = Question.create(question_params) + @question = Question.create(process_question_params) if @question.persisted? redirect_to admin_questions_path, flash: { notice: "Sucessfully created question" } @@ -34,7 +34,7 @@ module Admin @quizzes = Quiz.all @question = Question.find(params[:question_id]) - if @question.update_attributes(question_params) + if @question.update_attributes(process_question_params) redirect_to admin_question_path(@question.to_i), flash: { notice: "Sucessfully updated question" } else @@ -46,7 +46,19 @@ module Admin private def question_params - params.require(:question).permit(:quiz_id, :question, :category, :input_type, :input_options, :sort) + params.require(:question).permit( + :quiz_id, :question, :category, :input_type, :sort, :active, :input_options, + multi_choice: [], live_code: [:later, :html, :css, :js, :text] + ) + end + + def process_question_params + question = question_params + question[:input_options] = question_params[:multi_choice] unless question_params[:multi_choice].nil? + question[:input_options] = question_params[:live_coder] unless question_params[:live_coder].nil? + question.delete(:multi_choice) + question.delete(:live_coder) + question end end end diff --git a/app/controllers/quiz_controller.rb b/app/controllers/quiz_controller.rb index d604fed..016bd76 100644 --- a/app/controllers/quiz_controller.rb +++ b/app/controllers/quiz_controller.rb @@ -86,6 +86,7 @@ class QuizController < ApplicationController end end + # TODO: maybe a better way to do this. See Admin/QuestionController#process_question_params def process_text @answer.update(answer: answer_params[:text], saved: params.key?(:save),