app/controllers/questionnaires_controller.rb
def create
    questionnaire_private = params[:questionnaire][:private] == "true"
    display_type = params[:questionnaire][:type].split('Questionnaire')[0]
    @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]
    begin
      @questionnaire.private = questionnaire_private
      @questionnaire.name = params[:questionnaire][:name]
      @questionnaire.instructor_id = session[:user].id
      @questionnaire.min_question_score = params[:questionnaire][:min_question_score]
      @questionnaire.max_question_score = params[:questionnaire][:max_question_score]
      @questionnaire.type = params[:questionnaire][:type]
      # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.
      # In the future, we need to write migration files to make them consistency.
      case display_type
      when 'AuthorFeedback'
        display_type = 'Author%Feedback'
      when 'CourseSurvey'
        display_type = 'Course%Survey'
      when 'TeammateReview'
        display_type = 'Teammate%Review'
      when 'GlobalSurvey'
        display_type = 'Global%Survey'
      when 'AssignmentSurvey'
        display_type = 'Assignment%Survey'
      end
      @questionnaire.display_type = display_type
      @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL
      @questionnaire.save
      # Create node
      tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first
      parent = FolderNode.find_by(node_object_id: tree_folder.id)
      QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')
      flash[:success] = 'You have successfully created a questionnaire!'
    rescue StandardError
      flash[:error] = $ERROR_INFO
    end
    redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id
  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)
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 create
    questionnaire_private = params[:questionnaire][:private] == "true"
    display_type = params[:questionnaire][:type].split('Questionnaire')[0]
    @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]
    begin
      @questionnaire.private = questionnaire_private
      @questionnaire.name = params[:questionnaire][:name]
      @questionnaire.instructor_id = session[:user].id
      @questionnaire.min_question_score = params[:questionnaire][:min_question_score]
      @questionnaire.max_question_score = params[:questionnaire][:max_question_score]
      @questionnaire.type = params[:questionnaire][:type]
      case display_type
      when 'AuthorFeedback'
        display_type = 'Author%Feedback'
      when 'CourseSurvey'
        display_type = 'Course%Survey'
      when 'TeammateReview'
        display_type = 'Teammate%Review'
      when 'GlobalSurvey'
        display_type = 'Global%Survey'
      when 'AssignmentSurvey'
        display_type = 'Assignment%Survey'
      end
      @questionnaire.display_type = display_type
      @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL
      @questionnaire.save
      tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first
      parent = FolderNode.find_by(node_object_id: tree_folder.id)
      QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')
      flash[:success] = 'You have successfully created a questionnaire!'
    rescue StandardError
      flash[:error] = $ERROR_INFO
    end
    redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id
  end
def create questionnaire_private = params [ :questionnaire ] [ :private ] == "true" display_type = params [ :questionnaire ] [ :type ] . split ( 'Questionnaire' ) [ 0 ] @questionnaire = Object . const_get ( params [ :questionnaire ] [ :type ] ) . new if Questionnaire :: QUESTIONNAIRE_TYPES . include? params [ :questionnaire ] [ :type ] begin @questionnaire . private = questionnaire_private @questionnaire . name = params [ :questionnaire ] [ :name ] @questionnaire . instructor_id = session [ :user ] . id @questionnaire . min_question_score = params [ :questionnaire ] [ :min_question_score ] @questionnaire . max_question_score = params [ :questionnaire ] [ :max_question_score ] @questionnaire . type = params [ :questionnaire ] [ :type ] case display_type when 'AuthorFeedback' display_type = 'Author%Feedback' when 'CourseSurvey' display_type = 'Course%Survey' when 'TeammateReview' display_type = 'Teammate%Review' when 'GlobalSurvey' display_type = 'Global%Survey' when 'AssignmentSurvey' display_type = 'Assignment%Survey' end @questionnaire . display_type = display_type @questionnaire . instruction_loc = Questionnaire :: DEFAULT_QUESTIONNAIRE_URL @questionnaire . save tree_folder = TreeFolder . where ( [ 'name like ?' , @questionnaire . display_type ] ) . first parent = FolderNode . find_by ( node_object_id : tree_folder . id ) QuestionnaireNode . create ( parent_id : parent . id , node_object_id : @questionnaire . id , type : 'QuestionnaireNode' ) flash [ :success ] = 'You have successfully created a questionnaire!' rescue StandardError flash [ :error ] = $ERROR_INFO end redirect_to controller : 'questionnaires' , action : 'edit' , id : @questionnaire . id 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 )
# Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent. # In the future, we need to write migration files to make them consistency. # Create node