app/controllers/questionnaires_controller.rb
# Controller for Questionnaire objects
# A Questionnaire can be of several types (QuestionnaireType)
# Each Questionnaire contains zero or more questions (Question)
# Generally a questionnaire is associated with an assignment (Assignment)
Controller for Questionnaire objects
A Questionnaire can be of several types (QuestionnaireType)
Each Questionnaire contains zero or more questions (Question)
Generally a questionnaire is associated with an assignment (Assignment)
Controller for Questionnaire objects A Questionnaire can be of several types ( QuestionnaireType ) Each Questionnaire contains zero or more questions ( Question ) Generally a questionnaire is associated with an assignment ( Assignment )
def valid_quiz
    num_quiz_questions = Assignment.find(params[:aid]).num_quiz_questions
    valid = "valid"
    (1..num_quiz_questions).each do |i|
      if params[:questionnaire][:name] == ""
        valid = "Please specify quiz name (please do not use your name or id)."
        break
      elsif !params.key?(:question_type) || !params[:question_type].key?(i.to_s) || params[:question_type][i.to_s][:type].nil?
        valid = "Please select a type for each question"
        break
      else
        @new_question = Object.const_get(params[:question_type][i.to_s][:type]).create(txt: '', type: params[:question_type][i.to_s][:type], break_before: true)
        @new_question.update_attributes(txt: params[:new_question][i.to_s])
        type = params[:question_type][i.to_s][:type]
        choice_info = params[:new_choices][i.to_s][type] 
        if choice_info.nil?
          valid = "Please select a correct answer for all questions"
          break
        else
          valid = @new_question.isvalid(choice_info)
          break if valid != "valid"
        end
      end
    end
    valid
  end
def valid_quiz num_quiz_questions = Assignment . find ( params [ :aid ] ) . num_quiz_questions valid = "valid" ( 1 .. num_quiz_questions ) . each do | i | if params [ :questionnaire ] [ :name ] == "" valid = "Please specify quiz name (please do not use your name or id)." break elsif ! params . key? ( :question_type ) || ! params [ :question_type ] . key? ( i . to_s ) || params [ :question_type ] [ i . to_s ] [ :type ] . nil? valid = "Please select a type for each question" break else @new_question = Object . const_get ( params [ :question_type ] [ i . to_s ] [ :type ] ) . create ( txt : '' , type : params [ :question_type ] [ i . to_s ] [ :type ] , break_before : true ) @new_question . update_attributes ( txt : params [ :new_question ] [ i . to_s ] ) type = params [ :question_type ] [ i . to_s ] [ :type ] choice_info = params [ :new_choices ] [ i . to_s ] [ type ] if choice_info . nil? valid = "Please select a correct answer for all questions" break else valid = @new_question . isvalid ( choice_info ) break if valid != "valid" end end end valid end
Controller for Questionnaire objects
A Questionnaire can be of several types (QuestionnaireType)
Each Questionnaire contains zero or more questions (Question)
Generally a questionnaire is associated with an assignment (Assignment)
Controller for Questionnaire objects A Questionnaire can be of several types ( QuestionnaireType ) Each Questionnaire contains zero or more questions ( Question ) Generally a questionnaire is associated with an assignment ( Assignment )
# questionnaire name is not specified # A type isnt selected for a question # choice info for one question of its type