app/controllers/questionnaires_controller.rb
def save_choices(questionnaire_id)
    if params[:new_question] and params[:new_choices]
      questions = Question.where(questionnaire_id: questionnaire_id)
      questionnum = 1

      for question in questions
        q_type = params[:question_type][questionnum.to_s][:type]
        for choice_key in params[:new_choices][questionnum.to_s][q_type].keys
          score = if params[:new_choices][questionnum.to_s][q_type][choice_key]["weight"] == 1.to_s
                    1
                  else
                    0
                  end

          if q_type == "TrueFalse"
            if params[:new_choices][questionnum.to_s][q_type][1.to_s][:iscorrect] == choice_key
              q = QuizQuestionChoice.new(txt: "True", iscorrect: "true", question_id: question.id)
              q.save
              q = QuizQuestionChoice.new(txt: "False", iscorrect: "false", question_id: question.id)
              q.save
            else
              q = QuizQuestionChoice.new(txt: "True", iscorrect: "false", question_id: question.id)
              q.save
              q = QuizQuestionChoice.new(txt: "False", iscorrect: "true", question_id: question.id)
              q.save
            end
          else
            iscorrect_s = if q_type == "MultipleChoiceCheckbox"
                            (params[:new_choices][questionnum.to_s][q_type][choice_key][:iscorrect] == 1.to_s).to_s
                          else
                            (params[:new_choices][questionnum.to_s][q_type][1.to_s][:iscorrect] == choice_key).to_s
                          end
            q = QuizQuestionChoice.new(quiz_question_choice_params(txt: params[:new_choices][questionnum.to_s][q_type][choice_key][:txt],
                                                                   iscorrect: iscorrect_s, question_id: question.id))
            q.save
          end
        end
        questionnum += 1
        question.weight = 1
      end
    end
  end
# method to save the choices associated with a question in a quiz to the database
# only for quiz questionnaire
method to save the choices associated with a question in a quiz to the database
only for quiz questionnaire
method to save the choices associated with a question in a quiz to the database only for quiz questionnaire
def save_choices(questionnaire_id)
    if params[:new_question] and params[:new_choices]
      questions = Question.where(questionnaire_id: questionnaire_id)
      questionnum = 1
      for question in questions
        q_type = params[:question_type][questionnum.to_s][:type]
        for choice_key in params[:new_choices][questionnum.to_s][q_type].keys
          score = if params[:new_choices][questionnum.to_s][q_type][choice_key]["weight"] == 1.to_s
                    1
                  else
                    0
                  end
          if q_type == "TrueFalse"
            if params[:new_choices][questionnum.to_s][q_type][1.to_s][:iscorrect] == choice_key
              q = QuizQuestionChoice.new(txt: "True", iscorrect: "true", question_id: question.id)
              q.save
              q = QuizQuestionChoice.new(txt: "False", iscorrect: "false", question_id: question.id)
              q.save
            else
              q = QuizQuestionChoice.new(txt: "True", iscorrect: "false", question_id: question.id)
              q.save
              q = QuizQuestionChoice.new(txt: "False", iscorrect: "true", question_id: question.id)
              q.save
            end
          else
            iscorrect_s = if q_type == "MultipleChoiceCheckbox"
                            (params[:new_choices][questionnum.to_s][q_type][choice_key][:iscorrect] == 1.to_s).to_s
                          else
                            (params[:new_choices][questionnum.to_s][q_type][1.to_s][:iscorrect] == choice_key).to_s
                          end
            q = QuizQuestionChoice.new(quiz_question_choice_params(txt: params[:new_choices][questionnum.to_s][q_type][choice_key][:txt],
                                                                   iscorrect: iscorrect_s, question_id: question.id))
            q.save
          end
        end
        questionnum += 1
        question.weight = 1
      end
    end
  end
def save_choices ( questionnaire_id ) if params [ :new_question ] and params [ :new_choices ] questions = Question . where ( questionnaire_id : questionnaire_id ) questionnum = 1 for question in questions q_type = params [ :question_type ] [ questionnum . to_s ] [ :type ] for choice_key in params [ :new_choices ] [ questionnum . to_s ] [ q_type ] . keys score = if params [ :new_choices ] [ questionnum . to_s ] [ q_type ] [ choice_key ] [ "weight" ] == 1 . to_s 1 else 0 end if q_type == "TrueFalse" if params [ :new_choices ] [ questionnum . to_s ] [ q_type ] [ 1 . to_s ] [ :iscorrect ] == choice_key q = QuizQuestionChoice . new ( txt : "True" , iscorrect : "true" , question_id : question . id ) q . save q = QuizQuestionChoice . new ( txt : "False" , iscorrect : "false" , question_id : question . id ) q . save else q = QuizQuestionChoice . new ( txt : "True" , iscorrect : "false" , question_id : question . id ) q . save q = QuizQuestionChoice . new ( txt : "False" , iscorrect : "true" , question_id : question . id ) q . save end else iscorrect_s = if q_type == "MultipleChoiceCheckbox" ( params [ :new_choices ] [ questionnum . to_s ] [ q_type ] [ choice_key ] [ :iscorrect ] == 1 . to_s ) . to_s else ( params [ :new_choices ] [ questionnum . to_s ] [ q_type ] [ 1 . to_s ] [ :iscorrect ] == choice_key ) . to_s end q = QuizQuestionChoice . new ( quiz_question_choice_params ( txt : params [ :new_choices ] [ questionnum . to_s ] [ q_type ] [ choice_key ] [ :txt ] , iscorrect : iscorrect_s , question_id : question . id ) ) q . save end end questionnum += 1 question . weight = 1 end end end
method to save the choices associated with a question in a quiz to the database
only for quiz questionnaire
method to save the choices associated with a question in a quiz to the database only for quiz questionnaire
questionnaire_id