updated params processing
This commit is contained in:
parent
6bbbaf4580
commit
77684b2c3e
@ -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
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user