<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ptrived</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ptrived"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Ptrived"/>
	<updated>2026-06-26T03:12:24Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_response_controller&amp;diff=101622</id>
		<title>CSC/ECE 517 Spring 2016/Refactor response controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_response_controller&amp;diff=101622"/>
		<updated>2016-04-02T01:26:31Z</updated>

		<summary type="html">&lt;p&gt;Ptrived: /* Instructions to test from GUI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1614. Refactoring Response Controller==&lt;br /&gt;
&lt;br /&gt;
This page provide the details of the changes done as part of the refactoring response controller project(E1614).&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===A brief overview of Expertiza===&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] project is a platform to create reusable learning objects through peer review. It is an open source project which uses [http://rubyonrails.org/ Ruby on Rails] framework.&lt;br /&gt;
&lt;br /&gt;
===Project Statement===&lt;br /&gt;
The main aim of this project was to refactor the response_controller. The following tasks were completed as part of refactoring in this project:&lt;br /&gt;
&lt;br /&gt;
* Moving variable declaration to right places.&lt;br /&gt;
* Removing unused variables.&lt;br /&gt;
* Fixing code duplication.&lt;br /&gt;
* Replacing if else block with switch statements.&lt;br /&gt;
* Remove the unreachable code.&lt;br /&gt;
&lt;br /&gt;
===About Response Controller===&lt;br /&gt;
The Response controller is responsible for the CRUD(Create, Read, Update and Delete) operations on responses. The users can fill out a questionnaire such as review rubric or feedback on the partner's contribution. So the ResponseController handles the various operations on the responses, which are objects that Expertiza creates when you fill out a questionnaire.&lt;br /&gt;
&lt;br /&gt;
===Changes done as part of refactoring===&lt;br /&gt;
====Moving variable declaration to right places====&lt;br /&gt;
There were two variables &amp;quot;msg&amp;quot; and &amp;quot;error_msg&amp;quot; in the create method which were declared and initialized to blank strings and then again assigned some string value before it was used in the method. So we moved the variable declaration to the place were it was used and removed the unnecessary variable declaration. Below if the code snippet for the changes done:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def create&lt;br /&gt;
    @map = ResponseMap.find(params[:id]) #assignment/review/metareview id is in params id&lt;br /&gt;
&lt;br /&gt;
    set_all_responses&lt;br /&gt;
&lt;br /&gt;
    #to save the response for ReviewResponseMap, a questionnaire_id is wrapped in the params&lt;br /&gt;
    if params[:review][:questionnaire_id]&lt;br /&gt;
      @questionnaire = Questionnaire.find(params[:review][:questionnaire_id])&lt;br /&gt;
      @round = params[:review][:round]&lt;br /&gt;
    else&lt;br /&gt;
      @round=nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # create the response&lt;br /&gt;
    if params[:isSubmit].eql?('Yes')&lt;br /&gt;
      is_submitted = true&lt;br /&gt;
    else&lt;br /&gt;
      is_submitted = false&lt;br /&gt;
    end&lt;br /&gt;
    @response = Response.create(:map_id =&amp;gt; @map.id, :additional_comment =&amp;gt; params[:review][:comments],:round =&amp;gt; @round, :is_submitted =&amp;gt; is_submitted)#,:version_num=&amp;gt;@version)&lt;br /&gt;
&lt;br /&gt;
    #Change the order for displaying questions for editing response views.&lt;br /&gt;
    questions=sort_questions(@questionnaire.questions)&lt;br /&gt;
&lt;br /&gt;
    if params[:responses]&lt;br /&gt;
       create_answers(params, questions)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #@map.save&lt;br /&gt;
    msg = &amp;quot;Your response was successfully saved.&amp;quot;&lt;br /&gt;
    error_msg=&amp;quot;Error&amp;quot;&lt;br /&gt;
    @response.email();&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'response', :action =&amp;gt; 'saving', :id =&amp;gt; @map.map_id, :return =&amp;gt; params[:return], :msg =&amp;gt; msg, :error_msg =&amp;gt; error_msg, :save_options =&amp;gt; params[:save_options]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removing unused variables====&lt;br /&gt;
There were some unused variables in this controller. The edit method contained a variable &amp;quot;array_not_empty&amp;quot; variable which was not used anywhere. So we removed the unused variables.&lt;br /&gt;
&lt;br /&gt;
====Fixing code duplication====&lt;br /&gt;
There was some duplicate code in the update method. So we removed the duplicate code and retained the code snippet inside the if block. Below is the modified code for the update method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  #Update the response and answers when student &amp;quot;edit&amp;quot; existing response&lt;br /&gt;
  def update&lt;br /&gt;
    return unless action_allowed?&lt;br /&gt;
&lt;br /&gt;
    # the response to be updated&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    msg = &amp;quot;&amp;quot;&lt;br /&gt;
    begin&lt;br /&gt;
      @map = @response.map&lt;br /&gt;
      @response.update_attribute('additional_comment', params[:review][:comments])&lt;br /&gt;
      if @map.type==&amp;quot;ReviewResponseMap&amp;quot; &amp;amp;&amp;amp; @response.round&lt;br /&gt;
        @questionnaire = @map.questionnaire(@response.round)&lt;br /&gt;
      elsif @map.type==&amp;quot;ReviewResponseMap&amp;quot;&lt;br /&gt;
        @questionnaire = @map.questionnaire(nil)&lt;br /&gt;
      else&lt;br /&gt;
        @questionnaire = @map.questionnaire&lt;br /&gt;
      end&lt;br /&gt;
      questions = @questionnaire.questions.sort { |a,b| a.seq &amp;lt;=&amp;gt; b.seq }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       questions=sort_questions(@questionnaire.questions)&lt;br /&gt;
       create_answers(params,questions)&lt;br /&gt;
      questions = @questionnaire.questions.sort { |a,b| a.seq &amp;lt;=&amp;gt; b.seq }&lt;br /&gt;
&lt;br /&gt;
      if !params[:responses].nil? # for some rubrics, there might be no questions but only file submission (Dr. Ayala's rubric)&lt;br /&gt;
        params[:responses].each_pair do |k, v|&lt;br /&gt;
          score = Answer.where(response_id: @response.id, question_id:  questions[k.to_i].id).first&lt;br /&gt;
          unless score&lt;br /&gt;
            score = Answer.create(:response_id =&amp;gt; @response.id, :question_id =&amp;gt; questions[k.to_i].id, :answer =&amp;gt; v[:score], :comments =&amp;gt; v[:comment])&lt;br /&gt;
          end&lt;br /&gt;
          score.update_attribute('answer', v[:score])&lt;br /&gt;
          score.update_attribute('comments', v[:comment])&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      if (params['isSubmit'] &amp;amp;&amp;amp; (params['isSubmit'].eql?'Yes'))&lt;br /&gt;
        # Update the submission flag.&lt;br /&gt;
        @response.update_attribute('is_submitted',true)&lt;br /&gt;
      else&lt;br /&gt;
        @response.update_attribute('is_submitted',false)&lt;br /&gt;
      end&lt;br /&gt;
    rescue&lt;br /&gt;
      msg = &amp;quot;Your response was not saved. Cause:189 #{$!}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'response', :action =&amp;gt; 'saving', :id =&amp;gt; @map.map_id, :return =&amp;gt; params[:return], :msg =&amp;gt; msg, :save_options =&amp;gt; params[:save_options]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replacing if else block with switch statements====&lt;br /&gt;
The redirection method used the if-else statements. The if-else block was replaced with switch statements. Below if is the code snippet for the redirection method after the code changes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def redirection&lt;br /&gt;
    flash[:error] = params[:error_msg] unless params[:error_msg] and params[:error_msg].empty?&lt;br /&gt;
    flash[:note] = params[:msg] unless params[:msg] and params[:msg].empty?&lt;br /&gt;
    @map = Response.find_by_map_id(params[:id])&lt;br /&gt;
&lt;br /&gt;
    case params[:return]&lt;br /&gt;
      when &amp;quot;feedback&amp;quot;&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'grades', :action =&amp;gt; 'view_my_scores', :id =&amp;gt; @map.reviewer.id&lt;br /&gt;
      when &amp;quot;teammate&amp;quot;&lt;br /&gt;
        redirect_to view_student_teams_path student_id: @map.reviewer.id&lt;br /&gt;
      when &amp;quot;instructor&amp;quot;&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'grades', :action =&amp;gt; 'view', :id =&amp;gt; @map.response_map.assignment.id&lt;br /&gt;
      when &amp;quot;assignment_edit&amp;quot;&lt;br /&gt;
        redirect_to controller: 'assignments', action: 'edit', id: @map.response_map.assignment.id&lt;br /&gt;
      else&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'student_review', :action =&amp;gt; 'list', :id =&amp;gt; @map.reviewer.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Remove the unreachable code====&lt;br /&gt;
In the action_allowed? method of the controller there was a case for the  &amp;quot;edit&amp;quot; case which was getting executed all the time making the second case block unreachable. Modified the code to use the proper case statements for &amp;quot;edit&amp;quot;, &amp;quot;delete&amp;quot; and &amp;quot;update&amp;quot;. Below is the code snippet for the action_allowed? method after the code changes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
      # Deny access to anyone except reviewer &amp;amp; author's team&lt;br /&gt;
      when 'edit'  # If response has been submitted, no further editing allowed&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
        if (response.is_submitted)&lt;br /&gt;
          return false&lt;br /&gt;
        end&lt;br /&gt;
      when 'delete','update'&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
      when 'view'&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        map = response.map&lt;br /&gt;
&lt;br /&gt;
        # if it is a review response map, all the members of revieweee team should be able to view the reponse (can be done from heat map)&lt;br /&gt;
        if map.is_a? ReviewResponseMap&lt;br /&gt;
          reviewee_team = AssignmentTeam.find(map.reviewee_id)&lt;br /&gt;
          current_user_id?(response.map.reviewer.user_id) || reviewee_team.has_user(current_user) || (['Administrator','Instructor','Teaching Assistant'].include? current_user.role.name)&lt;br /&gt;
        else&lt;br /&gt;
          current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        current_user&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instructions to test from GUI===&lt;br /&gt;
As the main motive of the project was refactoring the response controller, we list down below the steps to test the flows involved with response controller so as to make sure that nothing is broken due to changes done as part of refactoring and the functionality as expected.&lt;br /&gt;
====Testing review====&lt;br /&gt;
* Login as a student user.&lt;br /&gt;
* Click on the Assignments tab and Select the assignment you want to submit review for others work.&lt;br /&gt;
* In the assignments page click on others work and select one of the assignment for review.&lt;br /&gt;
* Click on Begin and then answer different questions which are presented in the review rubric.&lt;br /&gt;
* Once done with the review, click on Submit review to submit the review.&lt;br /&gt;
&lt;br /&gt;
====Testing peer review====&lt;br /&gt;
* Login as a student user.&lt;br /&gt;
* Click on the Assignments tab and select the assignment you want to submit the teammate review.&lt;br /&gt;
* Click on the your team option.&lt;br /&gt;
* In the teammates page, click on the Review option against the user you want to submit the feedback.&lt;br /&gt;
* Fill out the questionnaire presented in the teammate review rubric.&lt;br /&gt;
* Once done with the responses, click on Submit review to submit the review for the teammate.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/anuragshendge/expertiza Forked Repository for Expertiza Project]&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;/div&gt;</summary>
		<author><name>Ptrived</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_response_controller&amp;diff=101621</id>
		<title>CSC/ECE 517 Spring 2016/Refactor response controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_response_controller&amp;diff=101621"/>
		<updated>2016-04-02T01:23:13Z</updated>

		<summary type="html">&lt;p&gt;Ptrived: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1614. Refactoring Response Controller==&lt;br /&gt;
&lt;br /&gt;
This page provide the details of the changes done as part of the refactoring response controller project(E1614).&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===A brief overview of Expertiza===&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] project is a platform to create reusable learning objects through peer review. It is an open source project which uses [http://rubyonrails.org/ Ruby on Rails] framework.&lt;br /&gt;
&lt;br /&gt;
===Project Statement===&lt;br /&gt;
The main aim of this project was to refactor the response_controller. The following tasks were completed as part of refactoring in this project:&lt;br /&gt;
&lt;br /&gt;
* Moving variable declaration to right places.&lt;br /&gt;
* Removing unused variables.&lt;br /&gt;
* Fixing code duplication.&lt;br /&gt;
* Replacing if else block with switch statements.&lt;br /&gt;
* Remove the unreachable code.&lt;br /&gt;
&lt;br /&gt;
===About Response Controller===&lt;br /&gt;
The Response controller is responsible for the CRUD(Create, Read, Update and Delete) operations on responses. The users can fill out a questionnaire such as review rubric or feedback on the partner's contribution. So the ResponseController handles the various operations on the responses, which are objects that Expertiza creates when you fill out a questionnaire.&lt;br /&gt;
&lt;br /&gt;
===Changes done as part of refactoring===&lt;br /&gt;
====Moving variable declaration to right places====&lt;br /&gt;
There were two variables &amp;quot;msg&amp;quot; and &amp;quot;error_msg&amp;quot; in the create method which were declared and initialized to blank strings and then again assigned some string value before it was used in the method. So we moved the variable declaration to the place were it was used and removed the unnecessary variable declaration. Below if the code snippet for the changes done:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def create&lt;br /&gt;
    @map = ResponseMap.find(params[:id]) #assignment/review/metareview id is in params id&lt;br /&gt;
&lt;br /&gt;
    set_all_responses&lt;br /&gt;
&lt;br /&gt;
    #to save the response for ReviewResponseMap, a questionnaire_id is wrapped in the params&lt;br /&gt;
    if params[:review][:questionnaire_id]&lt;br /&gt;
      @questionnaire = Questionnaire.find(params[:review][:questionnaire_id])&lt;br /&gt;
      @round = params[:review][:round]&lt;br /&gt;
    else&lt;br /&gt;
      @round=nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # create the response&lt;br /&gt;
    if params[:isSubmit].eql?('Yes')&lt;br /&gt;
      is_submitted = true&lt;br /&gt;
    else&lt;br /&gt;
      is_submitted = false&lt;br /&gt;
    end&lt;br /&gt;
    @response = Response.create(:map_id =&amp;gt; @map.id, :additional_comment =&amp;gt; params[:review][:comments],:round =&amp;gt; @round, :is_submitted =&amp;gt; is_submitted)#,:version_num=&amp;gt;@version)&lt;br /&gt;
&lt;br /&gt;
    #Change the order for displaying questions for editing response views.&lt;br /&gt;
    questions=sort_questions(@questionnaire.questions)&lt;br /&gt;
&lt;br /&gt;
    if params[:responses]&lt;br /&gt;
       create_answers(params, questions)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #@map.save&lt;br /&gt;
    msg = &amp;quot;Your response was successfully saved.&amp;quot;&lt;br /&gt;
    error_msg=&amp;quot;Error&amp;quot;&lt;br /&gt;
    @response.email();&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'response', :action =&amp;gt; 'saving', :id =&amp;gt; @map.map_id, :return =&amp;gt; params[:return], :msg =&amp;gt; msg, :error_msg =&amp;gt; error_msg, :save_options =&amp;gt; params[:save_options]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removing unused variables====&lt;br /&gt;
There were some unused variables in this controller. The edit method contained a variable &amp;quot;array_not_empty&amp;quot; variable which was not used anywhere. So we removed the unused variables.&lt;br /&gt;
&lt;br /&gt;
====Fixing code duplication====&lt;br /&gt;
There was some duplicate code in the update method. So we removed the duplicate code and retained the code snippet inside the if block. Below is the modified code for the update method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  #Update the response and answers when student &amp;quot;edit&amp;quot; existing response&lt;br /&gt;
  def update&lt;br /&gt;
    return unless action_allowed?&lt;br /&gt;
&lt;br /&gt;
    # the response to be updated&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    msg = &amp;quot;&amp;quot;&lt;br /&gt;
    begin&lt;br /&gt;
      @map = @response.map&lt;br /&gt;
      @response.update_attribute('additional_comment', params[:review][:comments])&lt;br /&gt;
      if @map.type==&amp;quot;ReviewResponseMap&amp;quot; &amp;amp;&amp;amp; @response.round&lt;br /&gt;
        @questionnaire = @map.questionnaire(@response.round)&lt;br /&gt;
      elsif @map.type==&amp;quot;ReviewResponseMap&amp;quot;&lt;br /&gt;
        @questionnaire = @map.questionnaire(nil)&lt;br /&gt;
      else&lt;br /&gt;
        @questionnaire = @map.questionnaire&lt;br /&gt;
      end&lt;br /&gt;
      questions = @questionnaire.questions.sort { |a,b| a.seq &amp;lt;=&amp;gt; b.seq }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       questions=sort_questions(@questionnaire.questions)&lt;br /&gt;
       create_answers(params,questions)&lt;br /&gt;
      questions = @questionnaire.questions.sort { |a,b| a.seq &amp;lt;=&amp;gt; b.seq }&lt;br /&gt;
&lt;br /&gt;
      if !params[:responses].nil? # for some rubrics, there might be no questions but only file submission (Dr. Ayala's rubric)&lt;br /&gt;
        params[:responses].each_pair do |k, v|&lt;br /&gt;
          score = Answer.where(response_id: @response.id, question_id:  questions[k.to_i].id).first&lt;br /&gt;
          unless score&lt;br /&gt;
            score = Answer.create(:response_id =&amp;gt; @response.id, :question_id =&amp;gt; questions[k.to_i].id, :answer =&amp;gt; v[:score], :comments =&amp;gt; v[:comment])&lt;br /&gt;
          end&lt;br /&gt;
          score.update_attribute('answer', v[:score])&lt;br /&gt;
          score.update_attribute('comments', v[:comment])&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      if (params['isSubmit'] &amp;amp;&amp;amp; (params['isSubmit'].eql?'Yes'))&lt;br /&gt;
        # Update the submission flag.&lt;br /&gt;
        @response.update_attribute('is_submitted',true)&lt;br /&gt;
      else&lt;br /&gt;
        @response.update_attribute('is_submitted',false)&lt;br /&gt;
      end&lt;br /&gt;
    rescue&lt;br /&gt;
      msg = &amp;quot;Your response was not saved. Cause:189 #{$!}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'response', :action =&amp;gt; 'saving', :id =&amp;gt; @map.map_id, :return =&amp;gt; params[:return], :msg =&amp;gt; msg, :save_options =&amp;gt; params[:save_options]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replacing if else block with switch statements====&lt;br /&gt;
The redirection method used the if-else statements. The if-else block was replaced with switch statements. Below if is the code snippet for the redirection method after the code changes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def redirection&lt;br /&gt;
    flash[:error] = params[:error_msg] unless params[:error_msg] and params[:error_msg].empty?&lt;br /&gt;
    flash[:note] = params[:msg] unless params[:msg] and params[:msg].empty?&lt;br /&gt;
    @map = Response.find_by_map_id(params[:id])&lt;br /&gt;
&lt;br /&gt;
    case params[:return]&lt;br /&gt;
      when &amp;quot;feedback&amp;quot;&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'grades', :action =&amp;gt; 'view_my_scores', :id =&amp;gt; @map.reviewer.id&lt;br /&gt;
      when &amp;quot;teammate&amp;quot;&lt;br /&gt;
        redirect_to view_student_teams_path student_id: @map.reviewer.id&lt;br /&gt;
      when &amp;quot;instructor&amp;quot;&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'grades', :action =&amp;gt; 'view', :id =&amp;gt; @map.response_map.assignment.id&lt;br /&gt;
      when &amp;quot;assignment_edit&amp;quot;&lt;br /&gt;
        redirect_to controller: 'assignments', action: 'edit', id: @map.response_map.assignment.id&lt;br /&gt;
      else&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'student_review', :action =&amp;gt; 'list', :id =&amp;gt; @map.reviewer.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Remove the unreachable code====&lt;br /&gt;
In the action_allowed? method of the controller there was a case for the  &amp;quot;edit&amp;quot; case which was getting executed all the time making the second case block unreachable. Modified the code to use the proper case statements for &amp;quot;edit&amp;quot;, &amp;quot;delete&amp;quot; and &amp;quot;update&amp;quot;. Below is the code snippet for the action_allowed? method after the code changes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
      # Deny access to anyone except reviewer &amp;amp; author's team&lt;br /&gt;
      when 'edit'  # If response has been submitted, no further editing allowed&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
        if (response.is_submitted)&lt;br /&gt;
          return false&lt;br /&gt;
        end&lt;br /&gt;
      when 'delete','update'&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
      when 'view'&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        map = response.map&lt;br /&gt;
&lt;br /&gt;
        # if it is a review response map, all the members of revieweee team should be able to view the reponse (can be done from heat map)&lt;br /&gt;
        if map.is_a? ReviewResponseMap&lt;br /&gt;
          reviewee_team = AssignmentTeam.find(map.reviewee_id)&lt;br /&gt;
          current_user_id?(response.map.reviewer.user_id) || reviewee_team.has_user(current_user) || (['Administrator','Instructor','Teaching Assistant'].include? current_user.role.name)&lt;br /&gt;
        else&lt;br /&gt;
          current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        current_user&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instructions to test from GUI===&lt;br /&gt;
As the main motive of the project was refactoring the response controller, we list down below the steps to test the flows involved with response controller so as to make sure that nothing is broken due to changes done as part of refactoring and the functionality as expected.&lt;br /&gt;
====Testing review====&lt;br /&gt;
* Login as a student user.&lt;br /&gt;
* Click on the Assignment and Select the assignment you want to submit review for others work.&lt;br /&gt;
* In the assignments page click on others work and select one of the assignment for review.&lt;br /&gt;
* Click on Begin and then answer different questions which are presented in the review rubric.&lt;br /&gt;
* Once done with the review, click on Submit review to submit the review.&lt;br /&gt;
&lt;br /&gt;
=====Testing peer review=====&lt;br /&gt;
* &lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/anuragshendge/expertiza Forked Repository for Expertiza Project]&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;/div&gt;</summary>
		<author><name>Ptrived</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_response_controller&amp;diff=101476</id>
		<title>CSC/ECE 517 Spring 2016/Refactor response controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016/Refactor_response_controller&amp;diff=101476"/>
		<updated>2016-03-29T18:23:02Z</updated>

		<summary type="html">&lt;p&gt;Ptrived: Created page with &amp;quot;==E1614. Refactoring Response Controller==  This page provide the details of the changes done as part of the refactoring response controller project(E1614).  __TOC__  ===A brief ...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1614. Refactoring Response Controller==&lt;br /&gt;
&lt;br /&gt;
This page provide the details of the changes done as part of the refactoring response controller project(E1614).&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===A brief overview of Expertiza===&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] project is a platform to create reusable learning objects through peer review. It is an open source project which uses [http://rubyonrails.org/ Ruby on Rails] framework.&lt;br /&gt;
&lt;br /&gt;
===Project Statement===&lt;br /&gt;
The main aim of this project was to refactor the response_controller. The following tasks were completed as part of refactoring in this project:&lt;br /&gt;
&lt;br /&gt;
* Moving variable declaration to right places.&lt;br /&gt;
* Removing unused variables.&lt;br /&gt;
* Fixing code duplication.&lt;br /&gt;
* Replacing if else block with switch statements.&lt;br /&gt;
* Remove the unreachable code.&lt;br /&gt;
&lt;br /&gt;
===About Response Controller===&lt;br /&gt;
The Response controller is responsible for the CRUD(Create, Read, Update and Delete) operations on responses. The users can fill out a questionnaire such as review rubric or feedback on the partner's contribution. So the ResponseController handles the various operations on the responses, which are objects that Expertiza creates when you fill out a questionnaire.&lt;br /&gt;
&lt;br /&gt;
===Changes done as part of refactoring===&lt;br /&gt;
====Moving variable declaration to right places====&lt;br /&gt;
There were two variables &amp;quot;msg&amp;quot; and &amp;quot;error_msg&amp;quot; in the create method which were declared and initialized to blank strings and then again assigned some string value before it was used in the method. So we moved the variable declaration to the place were it was used and removed the unnecessary variable declaration. Below if the code snippet for the changes done:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def create&lt;br /&gt;
    @map = ResponseMap.find(params[:id]) #assignment/review/metareview id is in params id&lt;br /&gt;
&lt;br /&gt;
    set_all_responses&lt;br /&gt;
&lt;br /&gt;
    #to save the response for ReviewResponseMap, a questionnaire_id is wrapped in the params&lt;br /&gt;
    if params[:review][:questionnaire_id]&lt;br /&gt;
      @questionnaire = Questionnaire.find(params[:review][:questionnaire_id])&lt;br /&gt;
      @round = params[:review][:round]&lt;br /&gt;
    else&lt;br /&gt;
      @round=nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # create the response&lt;br /&gt;
    if params[:isSubmit].eql?('Yes')&lt;br /&gt;
      is_submitted = true&lt;br /&gt;
    else&lt;br /&gt;
      is_submitted = false&lt;br /&gt;
    end&lt;br /&gt;
    @response = Response.create(:map_id =&amp;gt; @map.id, :additional_comment =&amp;gt; params[:review][:comments],:round =&amp;gt; @round, :is_submitted =&amp;gt; is_submitted)#,:version_num=&amp;gt;@version)&lt;br /&gt;
&lt;br /&gt;
    #Change the order for displaying questions for editing response views.&lt;br /&gt;
    questions=sort_questions(@questionnaire.questions)&lt;br /&gt;
&lt;br /&gt;
    if params[:responses]&lt;br /&gt;
       create_answers(params, questions)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #@map.save&lt;br /&gt;
    msg = &amp;quot;Your response was successfully saved.&amp;quot;&lt;br /&gt;
    error_msg=&amp;quot;Error&amp;quot;&lt;br /&gt;
    @response.email();&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'response', :action =&amp;gt; 'saving', :id =&amp;gt; @map.map_id, :return =&amp;gt; params[:return], :msg =&amp;gt; msg, :error_msg =&amp;gt; error_msg, :save_options =&amp;gt; params[:save_options]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removing unused variables====&lt;br /&gt;
There were some unused variables in this controller. The edit method contained a variable &amp;quot;array_not_empty&amp;quot; variable which was not used anywhere. So we removed the unused variables.&lt;br /&gt;
&lt;br /&gt;
====Fixing code duplication====&lt;br /&gt;
There was some duplicate code in the update method. So we removed the duplicate code and retained the code snippet inside the if block. Below is the modified code for the update method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  #Update the response and answers when student &amp;quot;edit&amp;quot; existing response&lt;br /&gt;
  def update&lt;br /&gt;
    return unless action_allowed?&lt;br /&gt;
&lt;br /&gt;
    # the response to be updated&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    msg = &amp;quot;&amp;quot;&lt;br /&gt;
    begin&lt;br /&gt;
      @map = @response.map&lt;br /&gt;
      @response.update_attribute('additional_comment', params[:review][:comments])&lt;br /&gt;
      if @map.type==&amp;quot;ReviewResponseMap&amp;quot; &amp;amp;&amp;amp; @response.round&lt;br /&gt;
        @questionnaire = @map.questionnaire(@response.round)&lt;br /&gt;
      elsif @map.type==&amp;quot;ReviewResponseMap&amp;quot;&lt;br /&gt;
        @questionnaire = @map.questionnaire(nil)&lt;br /&gt;
      else&lt;br /&gt;
        @questionnaire = @map.questionnaire&lt;br /&gt;
      end&lt;br /&gt;
      questions = @questionnaire.questions.sort { |a,b| a.seq &amp;lt;=&amp;gt; b.seq }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       questions=sort_questions(@questionnaire.questions)&lt;br /&gt;
       create_answers(params,questions)&lt;br /&gt;
      questions = @questionnaire.questions.sort { |a,b| a.seq &amp;lt;=&amp;gt; b.seq }&lt;br /&gt;
&lt;br /&gt;
      if !params[:responses].nil? # for some rubrics, there might be no questions but only file submission (Dr. Ayala's rubric)&lt;br /&gt;
        params[:responses].each_pair do |k, v|&lt;br /&gt;
          score = Answer.where(response_id: @response.id, question_id:  questions[k.to_i].id).first&lt;br /&gt;
          unless score&lt;br /&gt;
            score = Answer.create(:response_id =&amp;gt; @response.id, :question_id =&amp;gt; questions[k.to_i].id, :answer =&amp;gt; v[:score], :comments =&amp;gt; v[:comment])&lt;br /&gt;
          end&lt;br /&gt;
          score.update_attribute('answer', v[:score])&lt;br /&gt;
          score.update_attribute('comments', v[:comment])&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      if (params['isSubmit'] &amp;amp;&amp;amp; (params['isSubmit'].eql?'Yes'))&lt;br /&gt;
        # Update the submission flag.&lt;br /&gt;
        @response.update_attribute('is_submitted',true)&lt;br /&gt;
      else&lt;br /&gt;
        @response.update_attribute('is_submitted',false)&lt;br /&gt;
      end&lt;br /&gt;
    rescue&lt;br /&gt;
      msg = &amp;quot;Your response was not saved. Cause:189 #{$!}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'response', :action =&amp;gt; 'saving', :id =&amp;gt; @map.map_id, :return =&amp;gt; params[:return], :msg =&amp;gt; msg, :save_options =&amp;gt; params[:save_options]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replacing if else block with switch statements====&lt;br /&gt;
The redirection method used the if-else statements. The if-else block was replaced with switch statements. Below if is the code snippet for the redirection method after the code changes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def redirection&lt;br /&gt;
    flash[:error] = params[:error_msg] unless params[:error_msg] and params[:error_msg].empty?&lt;br /&gt;
    flash[:note] = params[:msg] unless params[:msg] and params[:msg].empty?&lt;br /&gt;
    @map = Response.find_by_map_id(params[:id])&lt;br /&gt;
&lt;br /&gt;
    case params[:return]&lt;br /&gt;
      when &amp;quot;feedback&amp;quot;&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'grades', :action =&amp;gt; 'view_my_scores', :id =&amp;gt; @map.reviewer.id&lt;br /&gt;
      when &amp;quot;teammate&amp;quot;&lt;br /&gt;
        redirect_to view_student_teams_path student_id: @map.reviewer.id&lt;br /&gt;
      when &amp;quot;instructor&amp;quot;&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'grades', :action =&amp;gt; 'view', :id =&amp;gt; @map.response_map.assignment.id&lt;br /&gt;
      when &amp;quot;assignment_edit&amp;quot;&lt;br /&gt;
        redirect_to controller: 'assignments', action: 'edit', id: @map.response_map.assignment.id&lt;br /&gt;
      else&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'student_review', :action =&amp;gt; 'list', :id =&amp;gt; @map.reviewer.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Remove the unreachable code====&lt;br /&gt;
In the action_allowed? method of the controller there was a case for the  &amp;quot;edit&amp;quot; case which was getting executed all the time making the second case block unreachable. Modified the code to use the proper case statements for &amp;quot;edit&amp;quot;, &amp;quot;delete&amp;quot; and &amp;quot;update&amp;quot;. Below is the code snippet for the action_allowed? method after the code changes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
      # Deny access to anyone except reviewer &amp;amp; author's team&lt;br /&gt;
      when 'edit'  # If response has been submitted, no further editing allowed&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
        if (response.is_submitted)&lt;br /&gt;
          return false&lt;br /&gt;
        end&lt;br /&gt;
      when 'delete','update'&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
      when 'view'&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        map = response.map&lt;br /&gt;
&lt;br /&gt;
        # if it is a review response map, all the members of revieweee team should be able to view the reponse (can be done from heat map)&lt;br /&gt;
        if map.is_a? ReviewResponseMap&lt;br /&gt;
          reviewee_team = AssignmentTeam.find(map.reviewee_id)&lt;br /&gt;
          current_user_id?(response.map.reviewer.user_id) || reviewee_team.has_user(current_user) || (['Administrator','Instructor','Teaching Assistant'].include? current_user.role.name)&lt;br /&gt;
        else&lt;br /&gt;
          current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        current_user&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/anuragshendge/expertiza Forked Repository for Expertiza Project]&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;/div&gt;</summary>
		<author><name>Ptrived</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=101475</id>
		<title>CSC/ECE 517 Spring 2016</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2016&amp;diff=101475"/>
		<updated>2016-03-29T18:22:51Z</updated>

		<summary type="html">&lt;p&gt;Ptrived: /* Writing Assignment 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Active Job]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Calibration Assignment Submissions==&lt;br /&gt;
*[[Calibration Assignment Submission (OmniAuth)]]&lt;br /&gt;
*[[Calibration Assignment Submission (Patch_verb)]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Mozilla Implement HTML5 form validation]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Functional Tests for Questionnaire Controller]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016 / Expertiza Self-Review Feature]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor different question types from quiz feature]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Implement private browsing]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Write automated tests for WebDriver]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor sign_up_sheet_controller.rb and sign_up_topic.rb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Implement Common Parts of the CSSOM API]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Functional tests for assignment creation function]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/E1604. Functional tests for Calibration function]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor and write unit tests for question type.rb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Spring 2016/Refactor response controller]]&lt;/div&gt;</summary>
		<author><name>Ptrived</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ptrived&amp;diff=101141</id>
		<title>User:Ptrived</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ptrived&amp;diff=101141"/>
		<updated>2016-03-23T17:14:52Z</updated>

		<summary type="html">&lt;p&gt;Ptrived: /* E1614. Refactoring Response Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1614. Refactoring Response Controller==&lt;br /&gt;
&lt;br /&gt;
This page provide the details of the changes done as part of the refactoring response controller project(E1614).&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===A brief overview of Expertiza===&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] project is a platform to create reusable learning objects through peer review. It is an open source project which uses [http://rubyonrails.org/ Ruby on Rails] framework.&lt;br /&gt;
&lt;br /&gt;
===Project Statement===&lt;br /&gt;
The main aim of this project was to refactor the response_controller. The following tasks were completed as part of refactoring in this project:&lt;br /&gt;
&lt;br /&gt;
* Moving variable declaration to right places.&lt;br /&gt;
* Removing unused variables.&lt;br /&gt;
* Fixing code duplication.&lt;br /&gt;
* Replacing if else block with switch statements.&lt;br /&gt;
* Remove the unreachable code.&lt;br /&gt;
&lt;br /&gt;
===About Response Controller===&lt;br /&gt;
The Response controller is responsible for the CRUD(Create, Read, Update and Delete) operations on responses. The users can fill out a questionnaire such as review rubric or feedback on the partner's contribution. So the ResponseController handles the various operations on the responses, which are objects that Expertiza creates when you fill out a questionnaire.&lt;br /&gt;
&lt;br /&gt;
===Changes done as part of refactoring===&lt;br /&gt;
====Moving variable declaration to right places====&lt;br /&gt;
There were two variables &amp;quot;msg&amp;quot; and &amp;quot;error_msg&amp;quot; in the create method which were declared and initialized to blank strings and then again assigned some string value before it was used in the method. So we moved the variable declaration to the place were it was used and removed the unnecessary variable declaration. Below if the code snippet for the changes done:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def create&lt;br /&gt;
    @map = ResponseMap.find(params[:id]) #assignment/review/metareview id is in params id&lt;br /&gt;
&lt;br /&gt;
    set_all_responses&lt;br /&gt;
&lt;br /&gt;
    #to save the response for ReviewResponseMap, a questionnaire_id is wrapped in the params&lt;br /&gt;
    if params[:review][:questionnaire_id]&lt;br /&gt;
      @questionnaire = Questionnaire.find(params[:review][:questionnaire_id])&lt;br /&gt;
      @round = params[:review][:round]&lt;br /&gt;
    else&lt;br /&gt;
      @round=nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # create the response&lt;br /&gt;
    if params[:isSubmit].eql?('Yes')&lt;br /&gt;
      is_submitted = true&lt;br /&gt;
    else&lt;br /&gt;
      is_submitted = false&lt;br /&gt;
    end&lt;br /&gt;
    @response = Response.create(:map_id =&amp;gt; @map.id, :additional_comment =&amp;gt; params[:review][:comments],:round =&amp;gt; @round, :is_submitted =&amp;gt; is_submitted)#,:version_num=&amp;gt;@version)&lt;br /&gt;
&lt;br /&gt;
    #Change the order for displaying questions for editing response views.&lt;br /&gt;
    questions=sort_questions(@questionnaire.questions)&lt;br /&gt;
&lt;br /&gt;
    if params[:responses]&lt;br /&gt;
       create_answers(params, questions)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #@map.save&lt;br /&gt;
    msg = &amp;quot;Your response was successfully saved.&amp;quot;&lt;br /&gt;
    error_msg=&amp;quot;Error&amp;quot;&lt;br /&gt;
    @response.email();&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'response', :action =&amp;gt; 'saving', :id =&amp;gt; @map.map_id, :return =&amp;gt; params[:return], :msg =&amp;gt; msg, :error_msg =&amp;gt; error_msg, :save_options =&amp;gt; params[:save_options]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removing unused variables====&lt;br /&gt;
There were some unused variables in this controller. The edit method contained a variable &amp;quot;array_not_empty&amp;quot; variable which was not used anywhere. So we removed the unused variables.&lt;br /&gt;
&lt;br /&gt;
====Fixing code duplication====&lt;br /&gt;
There was some duplicate code in the update method. So we removed the duplicate code and retained the code snippet inside the if block. Below is the modified code for the update method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  #Update the response and answers when student &amp;quot;edit&amp;quot; existing response&lt;br /&gt;
  def update&lt;br /&gt;
    return unless action_allowed?&lt;br /&gt;
&lt;br /&gt;
    # the response to be updated&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    msg = &amp;quot;&amp;quot;&lt;br /&gt;
    begin&lt;br /&gt;
      @map = @response.map&lt;br /&gt;
      @response.update_attribute('additional_comment', params[:review][:comments])&lt;br /&gt;
      if @map.type==&amp;quot;ReviewResponseMap&amp;quot; &amp;amp;&amp;amp; @response.round&lt;br /&gt;
        @questionnaire = @map.questionnaire(@response.round)&lt;br /&gt;
      elsif @map.type==&amp;quot;ReviewResponseMap&amp;quot;&lt;br /&gt;
        @questionnaire = @map.questionnaire(nil)&lt;br /&gt;
      else&lt;br /&gt;
        @questionnaire = @map.questionnaire&lt;br /&gt;
      end&lt;br /&gt;
      questions = @questionnaire.questions.sort { |a,b| a.seq &amp;lt;=&amp;gt; b.seq }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       questions=sort_questions(@questionnaire.questions)&lt;br /&gt;
       create_answers(params,questions)&lt;br /&gt;
      questions = @questionnaire.questions.sort { |a,b| a.seq &amp;lt;=&amp;gt; b.seq }&lt;br /&gt;
&lt;br /&gt;
      if !params[:responses].nil? # for some rubrics, there might be no questions but only file submission (Dr. Ayala's rubric)&lt;br /&gt;
        params[:responses].each_pair do |k, v|&lt;br /&gt;
          score = Answer.where(response_id: @response.id, question_id:  questions[k.to_i].id).first&lt;br /&gt;
          unless score&lt;br /&gt;
            score = Answer.create(:response_id =&amp;gt; @response.id, :question_id =&amp;gt; questions[k.to_i].id, :answer =&amp;gt; v[:score], :comments =&amp;gt; v[:comment])&lt;br /&gt;
          end&lt;br /&gt;
          score.update_attribute('answer', v[:score])&lt;br /&gt;
          score.update_attribute('comments', v[:comment])&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      if (params['isSubmit'] &amp;amp;&amp;amp; (params['isSubmit'].eql?'Yes'))&lt;br /&gt;
        # Update the submission flag.&lt;br /&gt;
        @response.update_attribute('is_submitted',true)&lt;br /&gt;
      else&lt;br /&gt;
        @response.update_attribute('is_submitted',false)&lt;br /&gt;
      end&lt;br /&gt;
    rescue&lt;br /&gt;
      msg = &amp;quot;Your response was not saved. Cause:189 #{$!}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'response', :action =&amp;gt; 'saving', :id =&amp;gt; @map.map_id, :return =&amp;gt; params[:return], :msg =&amp;gt; msg, :save_options =&amp;gt; params[:save_options]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replacing if else block with switch statements====&lt;br /&gt;
The redirection method used the if-else statements. The if-else block was replaced with switch statements. Below if is the code snippet for the redirection method after the code changes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def redirection&lt;br /&gt;
    flash[:error] = params[:error_msg] unless params[:error_msg] and params[:error_msg].empty?&lt;br /&gt;
    flash[:note] = params[:msg] unless params[:msg] and params[:msg].empty?&lt;br /&gt;
    @map = Response.find_by_map_id(params[:id])&lt;br /&gt;
&lt;br /&gt;
    case params[:return]&lt;br /&gt;
      when &amp;quot;feedback&amp;quot;&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'grades', :action =&amp;gt; 'view_my_scores', :id =&amp;gt; @map.reviewer.id&lt;br /&gt;
      when &amp;quot;teammate&amp;quot;&lt;br /&gt;
        redirect_to view_student_teams_path student_id: @map.reviewer.id&lt;br /&gt;
      when &amp;quot;instructor&amp;quot;&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'grades', :action =&amp;gt; 'view', :id =&amp;gt; @map.response_map.assignment.id&lt;br /&gt;
      when &amp;quot;assignment_edit&amp;quot;&lt;br /&gt;
        redirect_to controller: 'assignments', action: 'edit', id: @map.response_map.assignment.id&lt;br /&gt;
      else&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'student_review', :action =&amp;gt; 'list', :id =&amp;gt; @map.reviewer.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Remove the unreachable code====&lt;br /&gt;
In the action_allowed? method of the controller there was a case for the  &amp;quot;edit&amp;quot; case which was getting executed all the time making the second case block unreachable. Modified the code to use the proper case statements for &amp;quot;edit&amp;quot;, &amp;quot;delete&amp;quot; and &amp;quot;update&amp;quot;. Below is the code snippet for the action_allowed? method after the code changes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
      # Deny access to anyone except reviewer &amp;amp; author's team&lt;br /&gt;
      when 'edit'  # If response has been submitted, no further editing allowed&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
        if (response.is_submitted)&lt;br /&gt;
          return false&lt;br /&gt;
        end&lt;br /&gt;
      when 'delete','update'&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
      when 'view'&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        map = response.map&lt;br /&gt;
&lt;br /&gt;
        # if it is a review response map, all the members of revieweee team should be able to view the reponse (can be done from heat map)&lt;br /&gt;
        if map.is_a? ReviewResponseMap&lt;br /&gt;
          reviewee_team = AssignmentTeam.find(map.reviewee_id)&lt;br /&gt;
          current_user_id?(response.map.reviewer.user_id) || reviewee_team.has_user(current_user) || (['Administrator','Instructor','Teaching Assistant'].include? current_user.role.name)&lt;br /&gt;
        else&lt;br /&gt;
          current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        current_user&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/anuragshendge/expertiza Forked Repository for Expertiza Project]&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;/div&gt;</summary>
		<author><name>Ptrived</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ptrived&amp;diff=101140</id>
		<title>User:Ptrived</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ptrived&amp;diff=101140"/>
		<updated>2016-03-23T17:11:42Z</updated>

		<summary type="html">&lt;p&gt;Ptrived: /* E1614. Refactoring Response Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1614. Refactoring Response Controller==&lt;br /&gt;
&lt;br /&gt;
This page provide the details of the changes done as part of the refactoring response controller project(E1614).&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===A brief overview of Expertiza===&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] project is a platform to create reusable learning objects through peer review. It is an open source project which uses [http://rubyonrails.org/ Ruby on Rails] framework.&lt;br /&gt;
&lt;br /&gt;
===Project Statement===&lt;br /&gt;
The main aim of this project was to refactor the response_controller. The following tasks were completed as part of refactoring in this project:&lt;br /&gt;
&lt;br /&gt;
* Moving variable declaration to right places.&lt;br /&gt;
* Removing unused variables.&lt;br /&gt;
* Fixing code duplication.&lt;br /&gt;
* Replacing if else block with switch statements.&lt;br /&gt;
* Remove the unreachable code.&lt;br /&gt;
&lt;br /&gt;
===About Response Controller===&lt;br /&gt;
The Response controller is responsible for the CRUD(Create, Read, Update and Delete) operations on responses. The users can fill out a questionnaire such as review rubric or feedback on the partner's contribution. So the ResponseController handles the various operations on the responses, which are objects that Expertiza creates when you fill out a questionnaire.&lt;br /&gt;
&lt;br /&gt;
===Changes done as part of refactoring===&lt;br /&gt;
====Moving variable declaration to right places====&lt;br /&gt;
There were two variables &amp;quot;msg&amp;quot; and &amp;quot;error_msg&amp;quot; in the create method which were declared and initialized to blank strings and then again assigned some string value before it was used in the method. So we moved the variable declaration to the place were it was used and removed the unnecessary variable declaration. Below if the code snippet for the changes done:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def create&lt;br /&gt;
    @map = ResponseMap.find(params[:id]) #assignment/review/metareview id is in params id&lt;br /&gt;
&lt;br /&gt;
    set_all_responses&lt;br /&gt;
&lt;br /&gt;
    #to save the response for ReviewResponseMap, a questionnaire_id is wrapped in the params&lt;br /&gt;
    if params[:review][:questionnaire_id]&lt;br /&gt;
      @questionnaire = Questionnaire.find(params[:review][:questionnaire_id])&lt;br /&gt;
      @round = params[:review][:round]&lt;br /&gt;
    else&lt;br /&gt;
      @round=nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # create the response&lt;br /&gt;
    if params[:isSubmit].eql?('Yes')&lt;br /&gt;
      is_submitted = true&lt;br /&gt;
    else&lt;br /&gt;
      is_submitted = false&lt;br /&gt;
    end&lt;br /&gt;
    @response = Response.create(:map_id =&amp;gt; @map.id, :additional_comment =&amp;gt; params[:review][:comments],:round =&amp;gt; @round, :is_submitted =&amp;gt; is_submitted)#,:version_num=&amp;gt;@version)&lt;br /&gt;
&lt;br /&gt;
    #Change the order for displaying questions for editing response views.&lt;br /&gt;
    questions=sort_questions(@questionnaire.questions)&lt;br /&gt;
&lt;br /&gt;
    if params[:responses]&lt;br /&gt;
       create_answers(params, questions)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #@map.save&lt;br /&gt;
    msg = &amp;quot;Your response was successfully saved.&amp;quot;&lt;br /&gt;
    error_msg=&amp;quot;Error&amp;quot;&lt;br /&gt;
    @response.email();&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'response', :action =&amp;gt; 'saving', :id =&amp;gt; @map.map_id, :return =&amp;gt; params[:return], :msg =&amp;gt; msg, :error_msg =&amp;gt; error_msg, :save_options =&amp;gt; params[:save_options]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removing unused variables====&lt;br /&gt;
There were some unused variables in this controller. The edit method contained a variable &amp;quot;array_not_empty&amp;quot; variable which was not used anywhere. So we removed the unused variables.&lt;br /&gt;
&lt;br /&gt;
====Fixing code duplication====&lt;br /&gt;
There was some duplicate code in the update method. So we removed the duplicate code and retained the code snippet inside the if block. Below is the modified code for the update method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  #Update the response and answers when student &amp;quot;edit&amp;quot; existing response&lt;br /&gt;
  def update&lt;br /&gt;
    return unless action_allowed?&lt;br /&gt;
&lt;br /&gt;
    # the response to be updated&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    msg = &amp;quot;&amp;quot;&lt;br /&gt;
    begin&lt;br /&gt;
      @map = @response.map&lt;br /&gt;
      @response.update_attribute('additional_comment', params[:review][:comments])&lt;br /&gt;
      if @map.type==&amp;quot;ReviewResponseMap&amp;quot; &amp;amp;&amp;amp; @response.round&lt;br /&gt;
        @questionnaire = @map.questionnaire(@response.round)&lt;br /&gt;
      elsif @map.type==&amp;quot;ReviewResponseMap&amp;quot;&lt;br /&gt;
        @questionnaire = @map.questionnaire(nil)&lt;br /&gt;
      else&lt;br /&gt;
        @questionnaire = @map.questionnaire&lt;br /&gt;
      end&lt;br /&gt;
      questions = @questionnaire.questions.sort { |a,b| a.seq &amp;lt;=&amp;gt; b.seq }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       questions=sort_questions(@questionnaire.questions)&lt;br /&gt;
       create_answers(params,questions)&lt;br /&gt;
      questions = @questionnaire.questions.sort { |a,b| a.seq &amp;lt;=&amp;gt; b.seq }&lt;br /&gt;
&lt;br /&gt;
      if !params[:responses].nil? # for some rubrics, there might be no questions but only file submission (Dr. Ayala's rubric)&lt;br /&gt;
        params[:responses].each_pair do |k, v|&lt;br /&gt;
          score = Answer.where(response_id: @response.id, question_id:  questions[k.to_i].id).first&lt;br /&gt;
          unless score&lt;br /&gt;
            score = Answer.create(:response_id =&amp;gt; @response.id, :question_id =&amp;gt; questions[k.to_i].id, :answer =&amp;gt; v[:score], :comments =&amp;gt; v[:comment])&lt;br /&gt;
          end&lt;br /&gt;
          score.update_attribute('answer', v[:score])&lt;br /&gt;
          score.update_attribute('comments', v[:comment])&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      if (params['isSubmit'] &amp;amp;&amp;amp; (params['isSubmit'].eql?'Yes'))&lt;br /&gt;
        # Update the submission flag.&lt;br /&gt;
        @response.update_attribute('is_submitted',true)&lt;br /&gt;
      else&lt;br /&gt;
        @response.update_attribute('is_submitted',false)&lt;br /&gt;
      end&lt;br /&gt;
    rescue&lt;br /&gt;
      msg = &amp;quot;Your response was not saved. Cause:189 #{$!}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'response', :action =&amp;gt; 'saving', :id =&amp;gt; @map.map_id, :return =&amp;gt; params[:return], :msg =&amp;gt; msg, :save_options =&amp;gt; params[:save_options]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replacing if else block with switch statements====&lt;br /&gt;
The redirection method used the if-else statements. The if-else block was replaced with switch statements. Below if is the code snippet for the redirection method after the code changes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def redirection&lt;br /&gt;
    flash[:error] = params[:error_msg] unless params[:error_msg] and params[:error_msg].empty?&lt;br /&gt;
    flash[:note] = params[:msg] unless params[:msg] and params[:msg].empty?&lt;br /&gt;
    @map = Response.find_by_map_id(params[:id])&lt;br /&gt;
&lt;br /&gt;
    case params[:return]&lt;br /&gt;
      when &amp;quot;feedback&amp;quot;&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'grades', :action =&amp;gt; 'view_my_scores', :id =&amp;gt; @map.reviewer.id&lt;br /&gt;
      when &amp;quot;teammate&amp;quot;&lt;br /&gt;
        redirect_to view_student_teams_path student_id: @map.reviewer.id&lt;br /&gt;
      when &amp;quot;instructor&amp;quot;&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'grades', :action =&amp;gt; 'view', :id =&amp;gt; @map.response_map.assignment.id&lt;br /&gt;
      when &amp;quot;assignment_edit&amp;quot;&lt;br /&gt;
        redirect_to controller: 'assignments', action: 'edit', id: @map.response_map.assignment.id&lt;br /&gt;
      else&lt;br /&gt;
        redirect_to :controller =&amp;gt; 'student_review', :action =&amp;gt; 'list', :id =&amp;gt; @map.reviewer.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Remove the unreachable code====&lt;br /&gt;
In the action_allowed? method of the controller there was a case for the  &amp;quot;edit&amp;quot; case which was getting executed all the time making the second case block unreachable. Modified the code to use the proper case statements for &amp;quot;edit&amp;quot;, &amp;quot;delete&amp;quot; and &amp;quot;update&amp;quot;. Below is the code snippet for the action_allowed? method after the code changes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
      # Deny access to anyone except reviewer &amp;amp; author's team&lt;br /&gt;
      when 'edit'  # If response has been submitted, no further editing allowed&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
        if (response.is_submitted)&lt;br /&gt;
          return false&lt;br /&gt;
        end&lt;br /&gt;
      when 'delete','update'&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
      when 'view'&lt;br /&gt;
        response = Response.find(params[:id])&lt;br /&gt;
        map = response.map&lt;br /&gt;
&lt;br /&gt;
        # if it is a review response map, all the members of revieweee team should be able to view the reponse (can be done from heat map)&lt;br /&gt;
        if map.is_a? ReviewResponseMap&lt;br /&gt;
          reviewee_team = AssignmentTeam.find(map.reviewee_id)&lt;br /&gt;
          current_user_id?(response.map.reviewer.user_id) || reviewee_team.has_user(current_user) || (['Administrator','Instructor','Teaching Assistant'].include? current_user.role.name)&lt;br /&gt;
        else&lt;br /&gt;
          current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        current_user&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ptrived</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ptrived&amp;diff=101139</id>
		<title>User:Ptrived</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ptrived&amp;diff=101139"/>
		<updated>2016-03-23T16:58:26Z</updated>

		<summary type="html">&lt;p&gt;Ptrived: /* E1614. Refactoring Response Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1614. Refactoring Response Controller==&lt;br /&gt;
&lt;br /&gt;
This page provide the details of the changes done as part of the refactoring response controller project(E1614).&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===A brief overview of Expertiza===&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] project is a platform to create reusable learning objects through peer review. It is an open source project which uses [http://rubyonrails.org/ Ruby on Rails] framework.&lt;br /&gt;
&lt;br /&gt;
===Project Statement===&lt;br /&gt;
The main aim of this project was to refactor the response_controller. The following tasks were completed as part of refactoring in this project:&lt;br /&gt;
&lt;br /&gt;
* Moving variable declaration to right places.&lt;br /&gt;
* Removing unused variables.&lt;br /&gt;
* Fixing code duplication.&lt;br /&gt;
* Replacing if else block with switch statements.&lt;br /&gt;
* Remove the unreachable code.&lt;br /&gt;
&lt;br /&gt;
===About Response Controller===&lt;br /&gt;
The Response controller is responsible for the CRUD(Create, Read, Update and Delete) operations on responses. The users can fill out a questionnaire such as review rubric or feedback on the partner's contribution. So the ResponseController handles the various operations on the responses, which are objects that Expertiza creates when you fill out a questionnaire.&lt;br /&gt;
&lt;br /&gt;
===Changes done as part of refactoring===&lt;br /&gt;
====Moving variable declaration to right places====&lt;br /&gt;
There were two variables &amp;quot;msg&amp;quot; and &amp;quot;error_msg&amp;quot; in the create method which were declared and initialized to blank strings and then again assigned some string value before it was used in the method. So we moved the variable declaration to the place were it was used and removed the unnecessary variable declaration. Below if the code snippet for the changes done:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def create&lt;br /&gt;
    @map = ResponseMap.find(params[:id]) #assignment/review/metareview id is in params id&lt;br /&gt;
&lt;br /&gt;
    set_all_responses&lt;br /&gt;
&lt;br /&gt;
    #to save the response for ReviewResponseMap, a questionnaire_id is wrapped in the params&lt;br /&gt;
    if params[:review][:questionnaire_id]&lt;br /&gt;
      @questionnaire = Questionnaire.find(params[:review][:questionnaire_id])&lt;br /&gt;
      @round = params[:review][:round]&lt;br /&gt;
    else&lt;br /&gt;
      @round=nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # create the response&lt;br /&gt;
    if params[:isSubmit].eql?('Yes')&lt;br /&gt;
      is_submitted = true&lt;br /&gt;
    else&lt;br /&gt;
      is_submitted = false&lt;br /&gt;
    end&lt;br /&gt;
    @response = Response.create(:map_id =&amp;gt; @map.id, :additional_comment =&amp;gt; params[:review][:comments],:round =&amp;gt; @round, :is_submitted =&amp;gt; is_submitted)#,:version_num=&amp;gt;@version)&lt;br /&gt;
&lt;br /&gt;
    #Change the order for displaying questions for editing response views.&lt;br /&gt;
    questions=sort_questions(@questionnaire.questions)&lt;br /&gt;
&lt;br /&gt;
    if params[:responses]&lt;br /&gt;
       create_answers(params, questions)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #@map.save&lt;br /&gt;
    msg = &amp;quot;Your response was successfully saved.&amp;quot;&lt;br /&gt;
    error_msg=&amp;quot;Error&amp;quot;&lt;br /&gt;
    @response.email();&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'response', :action =&amp;gt; 'saving', :id =&amp;gt; @map.map_id, :return =&amp;gt; params[:return], :msg =&amp;gt; msg, :error_msg =&amp;gt; error_msg, :save_options =&amp;gt; params[:save_options]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removing unused variables====&lt;br /&gt;
There were some unused variables in this controller. The edit method contained a variable &amp;quot;array_not_empty&amp;quot; variable which was not used anywhere. So we removed the unused variables.&lt;br /&gt;
&lt;br /&gt;
====Fixing code duplication====&lt;br /&gt;
There was some duplicate code in the update method. So we removed the duplicate code and retained the code snippet inside the if block. Below is the modified code for the update method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  #Update the response and answers when student &amp;quot;edit&amp;quot; existing response&lt;br /&gt;
  def update&lt;br /&gt;
    return unless action_allowed?&lt;br /&gt;
&lt;br /&gt;
    # the response to be updated&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    msg = &amp;quot;&amp;quot;&lt;br /&gt;
    begin&lt;br /&gt;
      @map = @response.map&lt;br /&gt;
      @response.update_attribute('additional_comment', params[:review][:comments])&lt;br /&gt;
      if @map.type==&amp;quot;ReviewResponseMap&amp;quot; &amp;amp;&amp;amp; @response.round&lt;br /&gt;
        @questionnaire = @map.questionnaire(@response.round)&lt;br /&gt;
      elsif @map.type==&amp;quot;ReviewResponseMap&amp;quot;&lt;br /&gt;
        @questionnaire = @map.questionnaire(nil)&lt;br /&gt;
      else&lt;br /&gt;
        @questionnaire = @map.questionnaire&lt;br /&gt;
      end&lt;br /&gt;
      questions = @questionnaire.questions.sort { |a,b| a.seq &amp;lt;=&amp;gt; b.seq }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       questions=sort_questions(@questionnaire.questions)&lt;br /&gt;
       create_answers(params,questions)&lt;br /&gt;
      questions = @questionnaire.questions.sort { |a,b| a.seq &amp;lt;=&amp;gt; b.seq }&lt;br /&gt;
&lt;br /&gt;
      if !params[:responses].nil? # for some rubrics, there might be no questions but only file submission (Dr. Ayala's rubric)&lt;br /&gt;
        params[:responses].each_pair do |k, v|&lt;br /&gt;
          score = Answer.where(response_id: @response.id, question_id:  questions[k.to_i].id).first&lt;br /&gt;
          unless score&lt;br /&gt;
            score = Answer.create(:response_id =&amp;gt; @response.id, :question_id =&amp;gt; questions[k.to_i].id, :answer =&amp;gt; v[:score], :comments =&amp;gt; v[:comment])&lt;br /&gt;
          end&lt;br /&gt;
          score.update_attribute('answer', v[:score])&lt;br /&gt;
          score.update_attribute('comments', v[:comment])&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      if (params['isSubmit'] &amp;amp;&amp;amp; (params['isSubmit'].eql?'Yes'))&lt;br /&gt;
        # Update the submission flag.&lt;br /&gt;
        @response.update_attribute('is_submitted',true)&lt;br /&gt;
      else&lt;br /&gt;
        @response.update_attribute('is_submitted',false)&lt;br /&gt;
      end&lt;br /&gt;
    rescue&lt;br /&gt;
      msg = &amp;quot;Your response was not saved. Cause:189 #{$!}&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'response', :action =&amp;gt; 'saving', :id =&amp;gt; @map.map_id, :return =&amp;gt; params[:return], :msg =&amp;gt; msg, :save_options =&amp;gt; params[:save_options]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ptrived</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ptrived&amp;diff=101138</id>
		<title>User:Ptrived</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ptrived&amp;diff=101138"/>
		<updated>2016-03-23T16:46:07Z</updated>

		<summary type="html">&lt;p&gt;Ptrived: /* Moving variable declaration to right places */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1614. Refactoring Response Controller==&lt;br /&gt;
&lt;br /&gt;
This page provide the details of the changes done as part of the refactoring response controller project(E1614).&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===A brief overview of Expertiza===&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] project is a platform to create reusable learning objects through peer review. It is an open source project which uses [http://rubyonrails.org/ Ruby on Rails] framework.&lt;br /&gt;
&lt;br /&gt;
===Project Statement===&lt;br /&gt;
The main aim of this project was to refactor the response_controller. The following tasks were completed as part of refactoring in this project:&lt;br /&gt;
&lt;br /&gt;
* Moving variable declaration to right places.&lt;br /&gt;
* Removing unused variables.&lt;br /&gt;
* Fixing code duplication.&lt;br /&gt;
* Replacing if else block with switch statements.&lt;br /&gt;
* Remove the unreachable code.&lt;br /&gt;
&lt;br /&gt;
===About Response Controller===&lt;br /&gt;
The Response controller is responsible for the CRUD(Create, Read, Update and Delete) operations on responses. The users can fill out a questionnaire such as review rubric or feedback on the partner's contribution. So the ResponseController handles the various operations on the responses, which are objects that Expertiza creates when you fill out a questionnaire.&lt;br /&gt;
&lt;br /&gt;
===Changes done as part of refactoring===&lt;br /&gt;
====Moving variable declaration to right places====&lt;br /&gt;
There were two variables &amp;quot;msg&amp;quot; and &amp;quot;error_msg&amp;quot; in the create method which were declared and initialized to blank strings and then again assigned some string value before it was used in the method. So we moved the variable declaration to the place were it was used and removed the unnecessary variable declaration. Below if the code snippet for the changes done:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def create&lt;br /&gt;
    @map = ResponseMap.find(params[:id]) #assignment/review/metareview id is in params id&lt;br /&gt;
&lt;br /&gt;
    set_all_responses&lt;br /&gt;
&lt;br /&gt;
    #to save the response for ReviewResponseMap, a questionnaire_id is wrapped in the params&lt;br /&gt;
    if params[:review][:questionnaire_id]&lt;br /&gt;
      @questionnaire = Questionnaire.find(params[:review][:questionnaire_id])&lt;br /&gt;
      @round = params[:review][:round]&lt;br /&gt;
    else&lt;br /&gt;
      @round=nil&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # create the response&lt;br /&gt;
    if params[:isSubmit].eql?('Yes')&lt;br /&gt;
      is_submitted = true&lt;br /&gt;
    else&lt;br /&gt;
      is_submitted = false&lt;br /&gt;
    end&lt;br /&gt;
    @response = Response.create(:map_id =&amp;gt; @map.id, :additional_comment =&amp;gt; params[:review][:comments],:round =&amp;gt; @round, :is_submitted =&amp;gt; is_submitted)#,:version_num=&amp;gt;@version)&lt;br /&gt;
&lt;br /&gt;
    #Change the order for displaying questions for editing response views.&lt;br /&gt;
    questions=sort_questions(@questionnaire.questions)&lt;br /&gt;
&lt;br /&gt;
    if params[:responses]&lt;br /&gt;
       create_answers(params, questions)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #@map.save&lt;br /&gt;
    msg = &amp;quot;Your response was successfully saved.&amp;quot;&lt;br /&gt;
    error_msg=&amp;quot;Error&amp;quot;&lt;br /&gt;
    @response.email();&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'response', :action =&amp;gt; 'saving', :id =&amp;gt; @map.map_id, :return =&amp;gt; params[:return], :msg =&amp;gt; msg, :error_msg =&amp;gt; error_msg, :save_options =&amp;gt; params[:save_options]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ptrived</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ptrived&amp;diff=101137</id>
		<title>User:Ptrived</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ptrived&amp;diff=101137"/>
		<updated>2016-03-23T16:44:55Z</updated>

		<summary type="html">&lt;p&gt;Ptrived: /* E1614. Refactoring Response Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1614. Refactoring Response Controller==&lt;br /&gt;
&lt;br /&gt;
This page provide the details of the changes done as part of the refactoring response controller project(E1614).&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===A brief overview of Expertiza===&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] project is a platform to create reusable learning objects through peer review. It is an open source project which uses [http://rubyonrails.org/ Ruby on Rails] framework.&lt;br /&gt;
&lt;br /&gt;
===Project Statement===&lt;br /&gt;
The main aim of this project was to refactor the response_controller. The following tasks were completed as part of refactoring in this project:&lt;br /&gt;
&lt;br /&gt;
* Moving variable declaration to right places.&lt;br /&gt;
* Removing unused variables.&lt;br /&gt;
* Fixing code duplication.&lt;br /&gt;
* Replacing if else block with switch statements.&lt;br /&gt;
* Remove the unreachable code.&lt;br /&gt;
&lt;br /&gt;
===About Response Controller===&lt;br /&gt;
The Response controller is responsible for the CRUD(Create, Read, Update and Delete) operations on responses. The users can fill out a questionnaire such as review rubric or feedback on the partner's contribution. So the ResponseController handles the various operations on the responses, which are objects that Expertiza creates when you fill out a questionnaire.&lt;br /&gt;
&lt;br /&gt;
===Changes done as part of refactoring===&lt;br /&gt;
====Moving variable declaration to right places====&lt;br /&gt;
There were two variables &amp;quot;msg&amp;quot; and &amp;quot;error_msg&amp;quot; in the create method which were declared and initialized to blank strings and then again assigned some string value before it was used in the method. So we moved the variable declaration to the place were it was used and removed the unnecessary variable declaration. Below if the code snippet for the changes done:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  Hello&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ptrived</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ptrived&amp;diff=101136</id>
		<title>User:Ptrived</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ptrived&amp;diff=101136"/>
		<updated>2016-03-23T16:37:37Z</updated>

		<summary type="html">&lt;p&gt;Ptrived: /* E1614. Refactoring Response Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1614. Refactoring Response Controller==&lt;br /&gt;
&lt;br /&gt;
This page provide the details of the changes done as part of the refactoring response controller project(E1614).&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===A brief overview of Expertiza===&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] project is a platform to create reusable learning objects through peer review. It is an open source project which uses [http://rubyonrails.org/ Ruby on Rails] framework.&lt;br /&gt;
&lt;br /&gt;
===Project Statement===&lt;br /&gt;
The main aim of this project was to refactor the response_controller. The following tasks were completed as part of refactoring in this project:&lt;br /&gt;
&lt;br /&gt;
* Moving variable declaration to right places.&lt;br /&gt;
* Removing unused variables.&lt;br /&gt;
* Fixing code duplication.&lt;br /&gt;
* Replacing if else block with switch statements.&lt;br /&gt;
* Remove the unreachable code.&lt;br /&gt;
&lt;br /&gt;
===About Response Controller===&lt;br /&gt;
The Response controller is responsible for the CRUD(Create, Read, Update and Delete) operations on responses. The users can fill out a questionnaire such as review rubric or feedback on the partner's contribution. So the ResponseController handles the various operations on the responses, which are objects that Expertiza creates when you fill out a questionnaire.&lt;br /&gt;
&lt;br /&gt;
===Changes done as part of refactoring===&lt;br /&gt;
====Moving variable declaration to right places====&lt;/div&gt;</summary>
		<author><name>Ptrived</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Ptrived&amp;diff=101135</id>
		<title>User:Ptrived</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Ptrived&amp;diff=101135"/>
		<updated>2016-03-23T16:28:20Z</updated>

		<summary type="html">&lt;p&gt;Ptrived: Created page with &amp;quot;==E1614. Refactoring Response Controller==  This page provide the details of the changes done as part of the refactoring response controller project(E1614).  __TOC__  ===A brief ...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1614. Refactoring Response Controller==&lt;br /&gt;
&lt;br /&gt;
This page provide the details of the changes done as part of the refactoring response controller project(E1614).&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===A brief overview of Expertiza===&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] project is a platform to create reusable learning objects through peer review. It is an open source project which uses [http://rubyonrails.org/ Ruby on Rails] framework.&lt;br /&gt;
&lt;br /&gt;
===Project Statement===&lt;br /&gt;
The main aim of this project was to refactor the response_controller. The following tasks were completed as part of refactoring in this project:&lt;br /&gt;
&lt;br /&gt;
* Moving variable declaration to right places.&lt;br /&gt;
* Removing unused variables.&lt;br /&gt;
* Fixing code duplication.&lt;br /&gt;
* Replacing if else block with switch statements.&lt;br /&gt;
* Remove the unreachable code.&lt;/div&gt;</summary>
		<author><name>Ptrived</name></author>
	</entry>
</feed>