app/controllers/questionnaires_controller.rb
def new_quiz
    valid_request = true
    @assignment_id = params[:aid] # creating an instance variable to hold the assignment id
    @participant_id = params[:pid] # creating an instance variable to hold the participant id
    assignment = Assignment.find(@assignment_id)
    if !assignment.require_quiz? # flash error if this assignment does not require quiz
      flash[:error] = "This assignment does not support the quizzing feature."
      valid_request = false
    else
      team = AssignmentParticipant.find(@participant_id).team

      if team.nil? # flash error if this current participant does not have a team
        flash[:error] = "You should create or join a team first."
        valid_request = false
      else
        if assignment.topics? && team.topic.nil? # flash error if this assignment has topic but current team does not have a topic
          flash[:error] = "Your team should have a topic."
          valid_request = false
        end
      end
    end

    if valid_request && Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])
      @questionnaire = Object.const_get(params[:model]).new
      @questionnaire.private = params[:private]
      @questionnaire.min_question_score = 0
      @questionnaire.max_question_score = 1

      render :new_quiz
    else
      redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]
    end
  end
# define a new quiz questionnaire
# method invoked by the view
define a new quiz questionnaire
method invoked by the view
define a new quiz questionnaire method invoked by the view
def new_quiz
    valid_request = true
    @assignment_id = params[:aid] 
    @participant_id = params[:pid] 
    assignment = Assignment.find(@assignment_id)
    if !assignment.require_quiz? 
      flash[:error] = "This assignment does not support the quizzing feature."
      valid_request = false
    else
      team = AssignmentParticipant.find(@participant_id).team
      if team.nil? 
        flash[:error] = "You should create or join a team first."
        valid_request = false
      else
        if assignment.topics? && team.topic.nil? 
          flash[:error] = "Your team should have a topic."
          valid_request = false
        end
      end
    end
    if valid_request && Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])
      @questionnaire = Object.const_get(params[:model]).new
      @questionnaire.private = params[:private]
      @questionnaire.min_question_score = 0
      @questionnaire.max_question_score = 1
      render :new_quiz
    else
      redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]
    end
  end
def new_quiz valid_request = true @assignment_id = params [ :aid ] @participant_id = params [ :pid ] assignment = Assignment . find ( @assignment_id ) if ! assignment . require_quiz? flash [ :error ] = "This assignment does not support the quizzing feature." valid_request = false else team = AssignmentParticipant . find ( @participant_id ) . team if team . nil? flash [ :error ] = "You should create or join a team first." valid_request = false else if assignment . topics? && team . topic . nil? flash [ :error ] = "Your team should have a topic." valid_request = false end end end if valid_request && Questionnaire :: QUESTIONNAIRE_TYPES . include? ( params [ :model ] ) @questionnaire = Object . const_get ( params [ :model ] ) . new @questionnaire . private = params [ :private ] @questionnaire . min_question_score = 0 @questionnaire . max_question_score = 1 render :new_quiz else redirect_to controller : 'submitted_content' , action : 'view' , id : params [ :pid ] end end
define a new quiz questionnaire
method invoked by the view
define a new quiz questionnaire method invoked by the view
# creating an instance variable to hold the assignment id # creating an instance variable to hold the participant id # flash error if this assignment does not require quiz # flash error if this current participant does not have a team # flash error if this assignment has topic but current team does not have a topic