<?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=Shjoshi2</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=Shjoshi2"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Shjoshi2"/>
	<updated>2026-04-16T23:43:19Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91203</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91203"/>
		<updated>2014-10-30T02:55:45Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Concise Report on Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 assignment_controller.rb&lt;br /&gt;
 sign_up_sheet_controller.rb&lt;br /&gt;
 assignment.rb&lt;br /&gt;
 sign_up_sheet.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The assignment model and controller are used to create and edit assignments.  It provides tabs for rubrics, review strategy, due dates, and topics. The sign_up_sheet model and controller handle operations on the topics associated with each assignment.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
The &amp;lt;b&amp;gt;Topics&amp;lt;/b&amp;gt; tab in the &amp;lt;b&amp;gt;Assignments --&amp;gt; Edit&amp;lt;/b&amp;gt; view  is not usable right now.  The functionality that displays topics also needs to be usable by the student view, since students also have to view the list of topics (when they sign up for a topic).  Instructor and student functionality is a little different: instructors can add topics and change the number of slots, but they can’t sign up for topics. The Topics tab needs to be fixed, edit/delete topic functionality is to be added for instructors and common/duplicate code needs to be refactored.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==Controller==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| 1&lt;br /&gt;
| create&lt;br /&gt;
| Fixed redirection after topic creation to Topics tab&lt;br /&gt;
| On successful creation of a topic, the action was merely redirecting to the assignments/edit view&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| update&lt;br /&gt;
| Fixed redirection after topic updation to Topics tab&lt;br /&gt;
| Once a topic was successfully edited, the view rendered was just a list of topics&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| edit&lt;br /&gt;
| Initialized @assignment_id variable&lt;br /&gt;
| The variable is used in the edit view&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; valign=&amp;quot;middle&amp;quot; |&lt;br /&gt;
destroy&lt;br /&gt;
| Renamed the 'delete' method to 'destroy'&lt;br /&gt;
| This was done for better Rails 4 routing compatibility&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Initialized the assignment_id parameter&lt;br /&gt;
| This is used further on and is not passed from the link URL&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Fixed redirection after topic deletion to Topics tab&lt;br /&gt;
| Once a topic was successfully deleted, the view rendered was just a list of topics&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Views==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:18%;&amp;quot;|View Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
| rowspan=&amp;quot;5&amp;quot; valign=&amp;quot;middle&amp;quot; |&lt;br /&gt;
_add_signup_topcis&lt;br /&gt;
| Fixed title&lt;br /&gt;
| The page title displayed for an instructor was &amp;quot;Sign-up sheet for ... &amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Commented out View/Manage bookmark links&lt;br /&gt;
| These links were broken, and according to existing code were not meant for the instructor view.&lt;br /&gt;
|-&lt;br /&gt;
| Added variable initialization for @sign_up_topics&lt;br /&gt;
| The variable was referenced further on in the view, which was causing an 'nil value' error&lt;br /&gt;
|-&lt;br /&gt;
| Fixed flash message rendering for new topic creation&lt;br /&gt;
| The flash message was rendering incorrectly with HTML tags visible on the web page&lt;br /&gt;
|-&lt;br /&gt;
| Added full path names to partial names&lt;br /&gt;
| The shared partials were also being used by views in the Assignments controller, so full paths were needed&lt;br /&gt;
|-&lt;br /&gt;
| _add_topics&lt;br /&gt;
| Added separation between the Import Topics and Manage Bookmarks links&lt;br /&gt;
| The two links were clumped together and it was difficult to distinguish between them&lt;br /&gt;
|-&lt;br /&gt;
| _actions&lt;br /&gt;
| Replaced rendering of the reserve_topic partial with the _all_actions partial&lt;br /&gt;
| The reserve_topic partial is no longer being used and is replaced by the newly created _all_actions partial&lt;br /&gt;
|-&lt;br /&gt;
| _all_actions&lt;br /&gt;
| Created this new partial&lt;br /&gt;
| We created the _all_actions partial to conditionally render the &amp;quot;Actions&amp;quot; table field for both instructors and students. This now also includes working links through which instructors or administrators can edit or delete topics.&lt;br /&gt;
|-&lt;br /&gt;
| _table_line&lt;br /&gt;
| Gave edit/delete rights to Super Admin&lt;br /&gt;
| The Super-Administrator user wasn't included in the list of users with these permissions&lt;br /&gt;
|-&lt;br /&gt;
| edit&lt;br /&gt;
| Modified title and included @assignment_id variable to be passed as a parameter variable to the update action&lt;br /&gt;
| The view was initially trying to access the params[:assignment_id] variable which was not getting initialized&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring view code into relevant views ===&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Cleaning up unused code ==&lt;br /&gt;
The Refactors mentioned above enable us to delete unused partials namely:&lt;br /&gt;
&lt;br /&gt;
*assignments controller partials :&lt;br /&gt;
**_add_signup_topics.html.erb&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&lt;br /&gt;
*signup_sheet_controller partials :&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
&lt;br /&gt;
===Instructor Role===&lt;br /&gt;
Log into the application with the user having instructor's role (user3, password). [http://152.46.18.5:3000/ VCL application link]&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and expand the assignments section. &lt;br /&gt;
&lt;br /&gt;
2. Hover over the options symbol adjacent to the assignment and select the edit icon from the popup.&lt;br /&gt;
&lt;br /&gt;
3. We have pre-created an assignment with multiple topics with id. 253, so you can click this link to edit it - http://152.46.18.5:3000/assignments/253/edit&lt;br /&gt;
&lt;br /&gt;
4. Click on topics tab.&lt;br /&gt;
&lt;br /&gt;
[[File:Topics tab.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
5. You can edit or delete any topic here as you are in instructor role.&lt;br /&gt;
&lt;br /&gt;
[[File:Edit-topic.png]]&lt;br /&gt;
&lt;br /&gt;
6.  Also you can undo, redo any changes you have made.&lt;br /&gt;
&lt;br /&gt;
[[File:Undo.png]]&lt;br /&gt;
&lt;br /&gt;
===Student Role===&lt;br /&gt;
1. Log into the application with a user with Student role (user10, password).&lt;br /&gt;
&lt;br /&gt;
2. We have added this student from the instructor view into assignment id. 253 that we used above. So this is accessible to the student. The name of the assignment appears in the &lt;br /&gt;
student view as Copy of assignment 1.&lt;br /&gt;
&lt;br /&gt;
[[File:Student-view.png]]&lt;br /&gt;
&lt;br /&gt;
3. Click on the Copy of assignment 1 -&amp;gt; SignupSheet and the student can see the edited topics for the assignment with a signup icon and no edit/delete options which are instructor specific.&lt;br /&gt;
&lt;br /&gt;
[[File:Signupsheet.png]]&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://152.46.18.5:3000/ VCL link] - This might not be available after Nov. 2014&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No The OSS project requirements doc (Fall 2014 - Expertiza)]&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91147</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91147"/>
		<updated>2014-10-30T02:01:42Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Additional Learning and Future Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 assignment_controller.rb&lt;br /&gt;
 sign_up_sheet_controller.rb&lt;br /&gt;
 assignment.rb&lt;br /&gt;
 sign_up_sheet.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The assignment model and controller are used to create and edit assignments.  It provides tabs for rubrics, review strategy, due dates, and topics. The sign_up_sheet model and controller handle operations on the topics associated with each assignment.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
The &amp;lt;b&amp;gt;Topics&amp;lt;/b&amp;gt; tab in the &amp;lt;b&amp;gt;Assignments --&amp;gt; Edit&amp;lt;/b&amp;gt; view  is not usable right now.  The functionality that displays topics also needs to be usable by the student view, since students also have to view the list of topics (when they sign up for a topic).  Instructor and student functionality is a little different: instructors can add topics and change the number of slots, but they can’t sign up for topics. The Topics tab needs to be fixed, edit/delete topic functionality is to be added for instructors and common/duplicate code needs to be refactored.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring view code into relevant views ===&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Cleaning up unused code ==&lt;br /&gt;
The Refactors mentioned above enable us to delete unused partials namely:&lt;br /&gt;
&lt;br /&gt;
*assignments controller partials :&lt;br /&gt;
**_add_signup_topics.html.erb&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&lt;br /&gt;
*signup_sheet_controller partials :&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
&lt;br /&gt;
===Instructor Role===&lt;br /&gt;
Log into the application with the user having instructor's role (user3, password). [http://152.46.18.5:3000/ VCL application link]&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and expand the assignments section. &lt;br /&gt;
&lt;br /&gt;
2. Hover over the options symbol adjacent to the assignment and select the edit icon from the popup.&lt;br /&gt;
&lt;br /&gt;
3. We have pre-created an assignment with multiple topics with id. 253, so you can click this link to edit it - http://152.46.18.5:3000/assignments/253/edit&lt;br /&gt;
&lt;br /&gt;
4. Click on topics tab.&lt;br /&gt;
&lt;br /&gt;
[[File:Topics tab.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
5. You can edit or delete any topic here as you are in instructor role.&lt;br /&gt;
&lt;br /&gt;
[[File:Edit-topic.png]]&lt;br /&gt;
&lt;br /&gt;
6.  Also you can undo, redo any changes you have made.&lt;br /&gt;
&lt;br /&gt;
[[File:Undo.png]]&lt;br /&gt;
&lt;br /&gt;
===Student Role===&lt;br /&gt;
1. Log into the application with a user with Student role (user10, password).&lt;br /&gt;
&lt;br /&gt;
2. We have added this student from the instructor view into assignment id. 253 that we used above. So this is accessible to the student. The name of the assignment appears in the &lt;br /&gt;
student view as Copy of assignment 1.&lt;br /&gt;
&lt;br /&gt;
[[File:Student-view.png]]&lt;br /&gt;
&lt;br /&gt;
3. Click on the Copy of assignment 1 -&amp;gt; SignupSheet and the student can see the edited topics for the assignment with a signup icon and no edit/delete options which are instructor specific.&lt;br /&gt;
&lt;br /&gt;
[[File:Signupsheet.png]]&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://152.46.18.5:3000/ VCL link] - This might not be available after Nov. 2014&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No The OSS project requirements doc (Fall 2014 - Expertiza)]&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91146</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91146"/>
		<updated>2014-10-30T02:01:18Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 assignment_controller.rb&lt;br /&gt;
 sign_up_sheet_controller.rb&lt;br /&gt;
 assignment.rb&lt;br /&gt;
 sign_up_sheet.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The assignment model and controller are used to create and edit assignments.  It provides tabs for rubrics, review strategy, due dates, and topics. The sign_up_sheet model and controller handle operations on the topics associated with each assignment.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
The &amp;lt;b&amp;gt;Topics&amp;lt;/b&amp;gt; tab in the &amp;lt;b&amp;gt;Assignments --&amp;gt; Edit&amp;lt;/b&amp;gt; view  is not usable right now.  The functionality that displays topics also needs to be usable by the student view, since students also have to view the list of topics (when they sign up for a topic).  Instructor and student functionality is a little different: instructors can add topics and change the number of slots, but they can’t sign up for topics. The Topics tab needs to be fixed, edit/delete topic functionality is to be added for instructors and common/duplicate code needs to be refactored.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring view code into relevant views ===&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Cleaning up unused code ==&lt;br /&gt;
The Refactors mentioned above enable us to delete unused partials namely:&lt;br /&gt;
&lt;br /&gt;
*assignments controller partials :&lt;br /&gt;
**_add_signup_topics.html.erb&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&lt;br /&gt;
*signup_sheet_controller partials :&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
&lt;br /&gt;
===Instructor Role===&lt;br /&gt;
Log into the application with the user having instructor's role (user3, password). [http://152.46.18.5:3000/ VCL application link]&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and expand the assignments section. &lt;br /&gt;
&lt;br /&gt;
2. Hover over the options symbol adjacent to the assignment and select the edit icon from the popup.&lt;br /&gt;
&lt;br /&gt;
3. We have pre-created an assignment with multiple topics with id. 253, so you can click this link to edit it - http://152.46.18.5:3000/assignments/253/edit&lt;br /&gt;
&lt;br /&gt;
4. Click on topics tab.&lt;br /&gt;
&lt;br /&gt;
[[File:Topics tab.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
5. You can edit or delete any topic here as you are in instructor role.&lt;br /&gt;
&lt;br /&gt;
[[File:Edit-topic.png]]&lt;br /&gt;
&lt;br /&gt;
6.  Also you can undo, redo any changes you have made.&lt;br /&gt;
&lt;br /&gt;
[[File:Undo.png]]&lt;br /&gt;
&lt;br /&gt;
===Student Role===&lt;br /&gt;
1. Log into the application with a user with Student role (user10, password).&lt;br /&gt;
&lt;br /&gt;
2. We have added this student from the instructor view into assignment id. 253 that we used above. So this is accessible to the student. The name of the assignment appears in the &lt;br /&gt;
student view as Copy of assignment 1.&lt;br /&gt;
&lt;br /&gt;
[[File:Student-view.png]]&lt;br /&gt;
&lt;br /&gt;
3. Click on the Copy of assignment 1 -&amp;gt; SignupSheet and the student can see the edited topics for the assignment with a signup icon and no edit/delete options which are instructor specific.&lt;br /&gt;
&lt;br /&gt;
[[File:Signupsheet.png]]&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://152.46.18.5:3000/ VCL link] - This might not be available after Nov. 2014&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No The OSS project requirements doc (Fall 2014 - Expertiza)]&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91144</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91144"/>
		<updated>2014-10-30T02:00:31Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Steps to verify changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 assignment_controller.rb&lt;br /&gt;
 sign_up_sheet_controller.rb&lt;br /&gt;
 assignment.rb&lt;br /&gt;
 sign_up_sheet.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The assignment model and controller are used to create and edit assignments.  It provides tabs for rubrics, review strategy, due dates, and topics. The sign_up_sheet model and controller handle operations on the topics associated with each assignment.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
The &amp;lt;b&amp;gt;Topics&amp;lt;/b&amp;gt; tab in the &amp;lt;b&amp;gt;Assignments --&amp;gt; Edit&amp;lt;/b&amp;gt; view  is not usable right now.  The functionality that displays topics also needs to be usable by the student view, since students also have to view the list of topics (when they sign up for a topic).  Instructor and student functionality is a little different: instructors can add topics and change the number of slots, but they can’t sign up for topics. The Topics tab needs to be fixed, edit/delete topic functionality is to be added for instructors and common/duplicate code needs to be refactored.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring view code into relevant views ===&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Cleaning up unused code ==&lt;br /&gt;
The Refactors mentioned above enable us to delete unused partials namely:&lt;br /&gt;
&lt;br /&gt;
*assignments controller partials :&lt;br /&gt;
**_add_signup_topics.html.erb&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&lt;br /&gt;
*signup_sheet_controller partials :&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
&lt;br /&gt;
===Instructor Role===&lt;br /&gt;
Log into the application with the user having instructor's role (user3, password). [http://152.46.18.5:3000/ VCL application link]&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and expand the assignments section. &lt;br /&gt;
&lt;br /&gt;
2. Hover over the options symbol adjacent to the assignment and select the edit icon from the popup.&lt;br /&gt;
&lt;br /&gt;
3. We have pre-created an assignment with multiple topics with id. 253, so you can click this link to edit it - http://152.46.18.5:3000/assignments/253/edit&lt;br /&gt;
&lt;br /&gt;
4. Click on topics tab.&lt;br /&gt;
&lt;br /&gt;
[[File:Topics tab.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
5. You can edit or delete any topic here as you are in instructor role.&lt;br /&gt;
&lt;br /&gt;
[[File:Edit-topic.png]]&lt;br /&gt;
&lt;br /&gt;
6.  Also you can undo, redo any changes you have made.&lt;br /&gt;
&lt;br /&gt;
[[File:Undo.png]]&lt;br /&gt;
&lt;br /&gt;
===Student Role===&lt;br /&gt;
1. Log into the application with a user with Student role (user10, password).&lt;br /&gt;
&lt;br /&gt;
2. We have added this student from the instructor view into assignment id. 253 that we used above. So this is accessible to the student. The name of the assignment appears in the &lt;br /&gt;
student view as Copy of assignment 1.&lt;br /&gt;
&lt;br /&gt;
[[File:Student-view.png]]&lt;br /&gt;
&lt;br /&gt;
3. Click on the Copy of assignment 1 -&amp;gt; SignupSheet and the student can see the edited topics for the assignment with a signup icon and no edit/delete options which are instructor specific.&lt;br /&gt;
&lt;br /&gt;
[[File:Signupsheet.png]]&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://152.46.18.5:3000/ VCL link] - This might not be available after Nov. 2014&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No The OSS project requirements doc (Fall 2014 - Expertiza)]&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Signupsheet.png&amp;diff=91143</id>
		<title>File:Signupsheet.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Signupsheet.png&amp;diff=91143"/>
		<updated>2014-10-30T02:00:12Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Student-view.png&amp;diff=91141</id>
		<title>File:Student-view.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Student-view.png&amp;diff=91141"/>
		<updated>2014-10-30T01:57:38Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Undo.png&amp;diff=91136</id>
		<title>File:Undo.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Undo.png&amp;diff=91136"/>
		<updated>2014-10-30T01:54:10Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91135</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91135"/>
		<updated>2014-10-30T01:51:35Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Steps to verify changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 assignment_controller.rb&lt;br /&gt;
 sign_up_sheet_controller.rb&lt;br /&gt;
 assignment.rb&lt;br /&gt;
 sign_up_sheet.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The assignment model and controller are used to create and edit assignments.  It provides tabs for rubrics, review strategy, due dates, and topics. The sign_up_sheet model and controller handle operations on the topics associated with each assignment.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
The &amp;lt;b&amp;gt;Topics&amp;lt;/b&amp;gt; tab in the &amp;lt;b&amp;gt;Assignments --&amp;gt; Edit&amp;lt;/b&amp;gt; view  is not usable right now.  The functionality that displays topics also needs to be usable by the student view, since students also have to view the list of topics (when they sign up for a topic).  Instructor and student functionality is a little different: instructors can add topics and change the number of slots, but they can’t sign up for topics. The Topics tab needs to be fixed, edit/delete topic functionality is to be added for instructors and common/duplicate code needs to be refactored.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring view code into relevant views ===&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Cleaning up unused code ==&lt;br /&gt;
The Refactors mentioned above enable us to delete unused partials namely:&lt;br /&gt;
&lt;br /&gt;
*assignments controller partials :&lt;br /&gt;
**_add_signup_topics.html.erb&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&lt;br /&gt;
*signup_sheet_controller partials :&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role (user3, password). [http://152.46.18.5:3000/ VCL application link]&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and expand the assignments section. &lt;br /&gt;
&lt;br /&gt;
2. Hover over the options symbol adjacent to the assignment and select the edit icon from the popup.&lt;br /&gt;
&lt;br /&gt;
3. We have pre-created an assignment with multiple topics with id. 253, so you can click this link to edit it - http://152.46.18.5:3000/assignments/253/edit&lt;br /&gt;
&lt;br /&gt;
4. Click on topics tab.&lt;br /&gt;
&lt;br /&gt;
[[File:Topics tab.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
5. You can edit or delete any topic here as you are in instructor role. Also you can undo, redo any changes you have made.&lt;br /&gt;
&lt;br /&gt;
[[File:Edit-topic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://152.46.18.5:3000/ VCL link] - This might not be available after Nov. 2014&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No The OSS project requirements doc (Fall 2014 - Expertiza)]&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Edit-topic.png&amp;diff=91134</id>
		<title>File:Edit-topic.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Edit-topic.png&amp;diff=91134"/>
		<updated>2014-10-30T01:51:14Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91132</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91132"/>
		<updated>2014-10-30T01:49:27Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Steps to verify changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 assignment_controller.rb&lt;br /&gt;
 sign_up_sheet_controller.rb&lt;br /&gt;
 assignment.rb&lt;br /&gt;
 sign_up_sheet.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The assignment model and controller are used to create and edit assignments.  It provides tabs for rubrics, review strategy, due dates, and topics. The sign_up_sheet model and controller handle operations on the topics associated with each assignment.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
The &amp;lt;b&amp;gt;Topics&amp;lt;/b&amp;gt; tab in the &amp;lt;b&amp;gt;Assignments --&amp;gt; Edit&amp;lt;/b&amp;gt; view  is not usable right now.  The functionality that displays topics also needs to be usable by the student view, since students also have to view the list of topics (when they sign up for a topic).  Instructor and student functionality is a little different: instructors can add topics and change the number of slots, but they can’t sign up for topics. The Topics tab needs to be fixed, edit/delete topic functionality is to be added for instructors and common/duplicate code needs to be refactored.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring view code into relevant views ===&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Cleaning up unused code ==&lt;br /&gt;
The Refactors mentioned above enable us to delete unused partials namely:&lt;br /&gt;
&lt;br /&gt;
*assignments controller partials :&lt;br /&gt;
**_add_signup_topics.html.erb&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&lt;br /&gt;
*signup_sheet_controller partials :&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role (user3, password). [http://152.46.18.5:3000/ VCL application link]&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and expand the assignments section. &lt;br /&gt;
&lt;br /&gt;
2. Hover over the options symbol adjacent to the assignment and select the edit icon from the popup.&lt;br /&gt;
&lt;br /&gt;
3. We have pre-created an assignment with multiple topics with id. 253, so you can click this link to edit it - http://152.46.18.5:3000/assignments/253/edit&lt;br /&gt;
&lt;br /&gt;
4. Click on topics tab.&lt;br /&gt;
&lt;br /&gt;
[[File:Topics tab.png]]&lt;br /&gt;
&lt;br /&gt;
5. You can edit or delete any topic here as you are in instructor role. Also you can undo, redo any changes you have made.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://152.46.18.5:3000/ VCL link] - This might not be available after Nov. 2014&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No The OSS project requirements doc (Fall 2014 - Expertiza)]&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Topics_tab.png&amp;diff=91131</id>
		<title>File:Topics tab.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Topics_tab.png&amp;diff=91131"/>
		<updated>2014-10-30T01:49:00Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91130</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91130"/>
		<updated>2014-10-30T01:48:32Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Steps to verify changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 assignment_controller.rb&lt;br /&gt;
 sign_up_sheet_controller.rb&lt;br /&gt;
 assignment.rb&lt;br /&gt;
 sign_up_sheet.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The assignment model and controller are used to create and edit assignments.  It provides tabs for rubrics, review strategy, due dates, and topics. The sign_up_sheet model and controller handle operations on the topics associated with each assignment.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
The &amp;lt;b&amp;gt;Topics&amp;lt;/b&amp;gt; tab in the &amp;lt;b&amp;gt;Assignments --&amp;gt; Edit&amp;lt;/b&amp;gt; view  is not usable right now.  The functionality that displays topics also needs to be usable by the student view, since students also have to view the list of topics (when they sign up for a topic).  Instructor and student functionality is a little different: instructors can add topics and change the number of slots, but they can’t sign up for topics. The Topics tab needs to be fixed, edit/delete topic functionality is to be added for instructors and common/duplicate code needs to be refactored.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring view code into relevant views ===&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Cleaning up unused code ==&lt;br /&gt;
The Refactors mentioned above enable us to delete unused partials namely:&lt;br /&gt;
&lt;br /&gt;
*assignments controller partials :&lt;br /&gt;
**_add_signup_topics.html.erb&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&lt;br /&gt;
*signup_sheet_controller partials :&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role (user3, password). [http://152.46.18.5:3000/ VCL application link]&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and expand the assignments section. &lt;br /&gt;
&lt;br /&gt;
2. Hover over the options symbol adjacent to the assignment and select the edit icon from the popup.&lt;br /&gt;
&lt;br /&gt;
3. We have pre-created an assignment with multiple topics with id. 253, so you can click this link to edit it - http://152.46.18.5:3000/assignments/253/edit&lt;br /&gt;
&lt;br /&gt;
4. Click on topics tab.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. You can edit or delete any topic here as you are in instructor role. Also you can undo, redo any changes you have made.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://152.46.18.5:3000/ VCL link] - This might not be available after Nov. 2014&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No The OSS project requirements doc (Fall 2014 - Expertiza)]&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91120</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91120"/>
		<updated>2014-10-30T01:41:10Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Steps to verify changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 assignment_controller.rb&lt;br /&gt;
 sign_up_sheet_controller.rb&lt;br /&gt;
 assignment.rb&lt;br /&gt;
 sign_up_sheet.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The assignment model and controller are used to create and edit assignments.  It provides tabs for rubrics, review strategy, due dates, and topics. The sign_up_sheet model and controller handle operations on the topics associated with each assignment.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
The &amp;lt;b&amp;gt;Topics&amp;lt;/b&amp;gt; tab in the &amp;lt;b&amp;gt;Assignments --&amp;gt; Edit&amp;lt;/b&amp;gt; view  is not usable right now.  The functionality that displays topics also needs to be usable by the student view, since students also have to view the list of topics (when they sign up for a topic).  Instructor and student functionality is a little different: instructors can add topics and change the number of slots, but they can’t sign up for topics. The Topics tab needs to be fixed, edit/delete topic functionality is to be added for instructors and common/duplicate code needs to be refactored.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring view code into relevant views ===&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Cleaning up unused code ==&lt;br /&gt;
The Refactors mentioned above enable us to delete unused partials namely:&lt;br /&gt;
&lt;br /&gt;
*assignments controller partials :&lt;br /&gt;
**_add_signup_topics.html.erb&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&lt;br /&gt;
*signup_sheet_controller partials :&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role (user3, password). [http://152.46.18.5:3000/ VCL application link]&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and hover over the assignment “StaggeredDeadlines_Refactoring”.&lt;br /&gt;
&lt;br /&gt;
2. Click on “New Topic”.&lt;br /&gt;
&lt;br /&gt;
3. Enter the details of the topic you want to create. Create at least 2 topics for better analysis of the project.&lt;br /&gt;
&lt;br /&gt;
[[File:AddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://152.46.18.5:3000/ VCL link] - This might not be available after Nov. 2014&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No The OSS project requirements doc (Fall 2014 - Expertiza)]&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91116</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91116"/>
		<updated>2014-10-30T01:39:15Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Case 2 : Cleaning up unused code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 assignment_controller.rb&lt;br /&gt;
 sign_up_sheet_controller.rb&lt;br /&gt;
 assignment.rb&lt;br /&gt;
 sign_up_sheet.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The assignment model and controller are used to create and edit assignments.  It provides tabs for rubrics, review strategy, due dates, and topics. The sign_up_sheet model and controller handle operations on the topics associated with each assignment.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
The &amp;lt;b&amp;gt;Topics&amp;lt;/b&amp;gt; tab in the &amp;lt;b&amp;gt;Assignments --&amp;gt; Edit&amp;lt;/b&amp;gt; view  is not usable right now.  The functionality that displays topics also needs to be usable by the student view, since students also have to view the list of topics (when they sign up for a topic).  Instructor and student functionality is a little different: instructors can add topics and change the number of slots, but they can’t sign up for topics. The Topics tab needs to be fixed, edit/delete topic functionality is to be added for instructors and common/duplicate code needs to be refactored.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring view code into relevant views ===&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Cleaning up unused code ==&lt;br /&gt;
The Refactors mentioned above enable us to delete unused partials namely:&lt;br /&gt;
&lt;br /&gt;
*assignments controller partials :&lt;br /&gt;
**_add_signup_topics.html.erb&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&lt;br /&gt;
*signup_sheet_controller partials :&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role or super user's role.&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and hover over the assignment “StaggeredDeadlines_Refactoring”.&lt;br /&gt;
&lt;br /&gt;
2. Click on “New Topic”.&lt;br /&gt;
&lt;br /&gt;
3. Enter the details of the topic you want to create. Create at least 2 topics for better analysis of the project.&lt;br /&gt;
&lt;br /&gt;
[[File:AddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://152.46.18.5:3000/ VCL link] - This might not be available after Nov. 2014&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No The OSS project requirements doc (Fall 2014 - Expertiza)]&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91115</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91115"/>
		<updated>2014-10-30T01:38:45Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* After Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 assignment_controller.rb&lt;br /&gt;
 sign_up_sheet_controller.rb&lt;br /&gt;
 assignment.rb&lt;br /&gt;
 sign_up_sheet.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The assignment model and controller are used to create and edit assignments.  It provides tabs for rubrics, review strategy, due dates, and topics. The sign_up_sheet model and controller handle operations on the topics associated with each assignment.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
The &amp;lt;b&amp;gt;Topics&amp;lt;/b&amp;gt; tab in the &amp;lt;b&amp;gt;Assignments --&amp;gt; Edit&amp;lt;/b&amp;gt; view  is not usable right now.  The functionality that displays topics also needs to be usable by the student view, since students also have to view the list of topics (when they sign up for a topic).  Instructor and student functionality is a little different: instructors can add topics and change the number of slots, but they can’t sign up for topics. The Topics tab needs to be fixed, edit/delete topic functionality is to be added for instructors and common/duplicate code needs to be refactored.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring view code into relevant views ===&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Cleaning up unused code ==&lt;br /&gt;
The Refactors mentioned above enable us to delete unused partials namely:&lt;br /&gt;
&lt;br /&gt;
*assignments controller partials :&lt;br /&gt;
**_add_signup_topics.html.erb&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&lt;br /&gt;
*signup_sheet_controller partials :&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
 &lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role or super user's role.&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and hover over the assignment “StaggeredDeadlines_Refactoring”.&lt;br /&gt;
&lt;br /&gt;
2. Click on “New Topic”.&lt;br /&gt;
&lt;br /&gt;
3. Enter the details of the topic you want to create. Create at least 2 topics for better analysis of the project.&lt;br /&gt;
&lt;br /&gt;
[[File:AddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://152.46.18.5:3000/ VCL link] - This might not be available after Nov. 2014&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No The OSS project requirements doc (Fall 2014 - Expertiza)]&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91114</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91114"/>
		<updated>2014-10-30T01:38:21Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* After Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 assignment_controller.rb&lt;br /&gt;
 sign_up_sheet_controller.rb&lt;br /&gt;
 assignment.rb&lt;br /&gt;
 sign_up_sheet.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The assignment model and controller are used to create and edit assignments.  It provides tabs for rubrics, review strategy, due dates, and topics. The sign_up_sheet model and controller handle operations on the topics associated with each assignment.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
The &amp;lt;b&amp;gt;Topics&amp;lt;/b&amp;gt; tab in the &amp;lt;b&amp;gt;Assignments --&amp;gt; Edit&amp;lt;/b&amp;gt; view  is not usable right now.  The functionality that displays topics also needs to be usable by the student view, since students also have to view the list of topics (when they sign up for a topic).  Instructor and student functionality is a little different: instructors can add topics and change the number of slots, but they can’t sign up for topics. The Topics tab needs to be fixed, edit/delete topic functionality is to be added for instructors and common/duplicate code needs to be refactored.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring view code into relevant views===&amp;lt;br&amp;gt;&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Cleaning up unused code ==&lt;br /&gt;
The Refactors mentioned above enable us to delete unused partials namely:&lt;br /&gt;
&lt;br /&gt;
*assignments controller partials :&lt;br /&gt;
**_add_signup_topics.html.erb&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&lt;br /&gt;
*signup_sheet_controller partials :&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
 &lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role or super user's role.&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and hover over the assignment “StaggeredDeadlines_Refactoring”.&lt;br /&gt;
&lt;br /&gt;
2. Click on “New Topic”.&lt;br /&gt;
&lt;br /&gt;
3. Enter the details of the topic you want to create. Create at least 2 topics for better analysis of the project.&lt;br /&gt;
&lt;br /&gt;
[[File:AddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://152.46.18.5:3000/ VCL link] - This might not be available after Nov. 2014&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No The OSS project requirements doc (Fall 2014 - Expertiza)]&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91105</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91105"/>
		<updated>2014-10-30T01:34:30Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 assignment_controller.rb&lt;br /&gt;
 sign_up_sheet_controller.rb&lt;br /&gt;
 assignment.rb&lt;br /&gt;
 sign_up_sheet.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The assignment model and controller are used to create and edit assignments.  It provides tabs for rubrics, review strategy, due dates, and topics. The sign_up_sheet model and controller handle operations on the topics associated with each assignment.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
The &amp;lt;b&amp;gt;Topics&amp;lt;/b&amp;gt; tab in the &amp;lt;b&amp;gt;Assignments --&amp;gt; Edit&amp;lt;/b&amp;gt; view  is not usable right now.  The functionality that displays topics also needs to be usable by the student view, since students also have to view the list of topics (when they sign up for a topic).  Instructor and student functionality is a little different: instructors can add topics and change the number of slots, but they can’t sign up for topics. The Topics tab needs to be fixed, edit/delete topic functionality is to be added for instructors and common/duplicate code needs to be refactored.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Refactoring view code into relevant views&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Cleaning up unused code ==&lt;br /&gt;
The Refactors mentioned above enable us to delete unused partials namely:&lt;br /&gt;
&lt;br /&gt;
*assignments controller partials :&lt;br /&gt;
**_add_signup_topics.html.erb&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&lt;br /&gt;
*signup_sheet_controller partials :&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
 &lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role or super user's role.&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and hover over the assignment “StaggeredDeadlines_Refactoring”.&lt;br /&gt;
&lt;br /&gt;
2. Click on “New Topic”.&lt;br /&gt;
&lt;br /&gt;
3. Enter the details of the topic you want to create. Create at least 2 topics for better analysis of the project.&lt;br /&gt;
&lt;br /&gt;
[[File:AddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://152.46.18.5:3000/ VCL link] - This might not be available after Nov. 2014&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No The OSS project requirements doc (Fall 2014 - Expertiza)]&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91102</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=91102"/>
		<updated>2014-10-30T01:31:42Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 assignment_controller.rb&lt;br /&gt;
 sign_up_sheet_controller.rb&lt;br /&gt;
 assignment.rb&lt;br /&gt;
 sign_up_sheet.rb&lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
The assignment model and controller are used to create and edit assignments.  It provides tabs for rubrics, review strategy, due dates, and topics. The sign_up_sheet model and controller handle operations on the topics associated with each assignment.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
The &amp;lt;b&amp;gt;Topics&amp;lt;/b&amp;gt; tab in the &amp;lt;b&amp;gt;Assignments --&amp;gt; Edit&amp;lt;/b&amp;gt; view  is not usable right now.  The functionality that displays topics also needs to be usable by the student view, since students also have to view the list of topics (when they sign up for a topic).  Instructor and student functionality is a little different: instructors can add topics and change the number of slots, but they can’t sign up for topics. The Topics tab needs to be fixed, edit/delete topic functionality is to be added for instructors and common/duplicate code needs to be refactored.&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Refactoring view code into relevant views&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Cleaning up unused code ==&lt;br /&gt;
The Refactors mentioned above enable us to delete unused partials namely:&lt;br /&gt;
&lt;br /&gt;
*assignments controller partials :&lt;br /&gt;
**_add_signup_topics.html.erb&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
&lt;br /&gt;
*signup_sheet_controller partials :&lt;br /&gt;
**_reserve_topic.html.erb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Similarly the method call is re-factored in various views.&lt;br /&gt;
For instance, for view _assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;% &amp;lt;b&amp;gt;if @assignment.staggered_deadline == true&amp;lt;/b&amp;gt; %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics_staggered'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Method Extraction  ==&lt;br /&gt;
&lt;br /&gt;
Improved readability by [http://sourcemaking.com/refactoring/extract-method extracting] two separate functionalities from the same method into separate methods with appropriate naming convention and responsibilities.&lt;br /&gt;
&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
The add_signup_topics calculated due dates for separate topics for a Staggered assignment with individual Topic deadlines.&lt;br /&gt;
&lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
   load_add_signup_topics(params[:id])&lt;br /&gt;
   if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
      &lt;br /&gt;
     &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
      #Render a view different for staggered deadlines assignment from the add_sign_up.html.erb&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The logic to calculate due_dates was moved to a separate method called assignment_due_date , as this is only valid for staggered assignments   &lt;br /&gt;
and hence it should be placed in a different method instead of merging it the add_signup_topics&lt;br /&gt;
 &lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
    load_add_signup_topics(params[:id])&lt;br /&gt;
  if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
     &lt;br /&gt;
   &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#Function call to set up due dates&lt;br /&gt;
      assignment_due_date&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
   #Render a view different from the add_sign_up.html.erb  , so rendering a view for staggered deadlines.&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assignment_due_date&lt;br /&gt;
     #below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==Case 3 : Modularize Code in application.rb==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
In the assignment.rb model, there exists one method(check_condition) which checks whether review, meta-review, etc are allowed or not. This method makes database calls to TopicDeadline table, DueDate and DeadlineType tables. Following is the code which was existing before the changes were made. It has the logic to find the nearest due date that hasn't passed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     drop_topic_deadline_id = DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      &lt;br /&gt;
      if topic_id&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                   topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
      else&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      next_due_date = DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
===After changes===&lt;br /&gt;
The database queries have been moved to their respective models. The queries to TopicDeadline table, DueDate table and DeadlineType table have been moved to their models. Below is the new code in assignments.rb model which calls TopicDeadline.rb, DueDate.rb and DeadlineType.rb respectively for the queries in their tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt; model&lt;br /&gt;
&lt;br /&gt;
 if self.staggered_deadline?&lt;br /&gt;
   next_due_date = TopicDeadline.find_next_due_date(topic_id,self.id)&lt;br /&gt;
 else&lt;br /&gt;
   next_due_date = DueDate.find_next_due_date(self.id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; defined in &amp;lt;b&amp;gt;topic_deadline.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
 def self.find_next_due_date(topic_id,assignment_id)&lt;br /&gt;
    drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
    if topic_id&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    else&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         assignment_id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;due_date.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_next_due_date(assignment_id&lt;br /&gt;
   drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
   DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                assignment_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_drop_topic_deadline_id&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;deadline_type.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_drop_topic_deadline_id()&lt;br /&gt;
   DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
== Case 4 : DeadCode Elimination in  sign_up_sheet_controller.rb ==&lt;br /&gt;
&lt;br /&gt;
The local variables topic_set and topic under the staggered deadline check statement were never used in the entire scope of the project , it introduced code smells. So it was checked if there was any reference to this code, and upon discovering it was not used anywhere, we decided to eliminate this [http://en.wikipedia.org/wiki/Dead_code_elimination deadcode].&lt;br /&gt;
 &lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      topic_set = Array.new&lt;br /&gt;
      topic = @sign_up_topic.id&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
 &lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role or super user's role.&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and hover over the assignment “StaggeredDeadlines_Refactoring”.&lt;br /&gt;
&lt;br /&gt;
2. Click on “New Topic”.&lt;br /&gt;
&lt;br /&gt;
3. Enter the details of the topic you want to create. Create at least 2 topics for better analysis of the project.&lt;br /&gt;
&lt;br /&gt;
[[File:AddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://152.46.18.5:3000/ VCL link] - This might not be available after Nov. 2014&lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No The OSS project requirements doc (Fall 2014 - Expertiza)]&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90759</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90759"/>
		<updated>2014-10-29T20:21:59Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
= Project Resources =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itsmylifesoham/expertiza GitHub Project Repository]&lt;br /&gt;
&lt;br /&gt;
[http://152.46.18.5:3000/ VCL IP Address]&lt;br /&gt;
&lt;br /&gt;
[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki]&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Refactoring view code into relevant views&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Cleaning up unused code ==&lt;br /&gt;
The Refactors mentioned above enable us to delete unused partials namely:&lt;br /&gt;
&lt;br /&gt;
assignments controller partials :&lt;br /&gt;
1. _add_signup_topics.html.erb&lt;br /&gt;
2. _reserve_topic.html.erb&lt;br /&gt;
&lt;br /&gt;
signup_sheet_controller partials :&lt;br /&gt;
1. _reserve_topic.html.erb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Similarly the method call is re-factored in various views.&lt;br /&gt;
For instance, for view _assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;% &amp;lt;b&amp;gt;if @assignment.staggered_deadline == true&amp;lt;/b&amp;gt; %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics_staggered'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Method Extraction  ==&lt;br /&gt;
&lt;br /&gt;
Improved readability by [http://sourcemaking.com/refactoring/extract-method extracting] two separate functionalities from the same method into separate methods with appropriate naming convention and responsibilities.&lt;br /&gt;
&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
The add_signup_topics calculated due dates for separate topics for a Staggered assignment with individual Topic deadlines.&lt;br /&gt;
&lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
   load_add_signup_topics(params[:id])&lt;br /&gt;
   if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
      &lt;br /&gt;
     &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
      #Render a view different for staggered deadlines assignment from the add_sign_up.html.erb&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The logic to calculate due_dates was moved to a separate method called assignment_due_date , as this is only valid for staggered assignments   &lt;br /&gt;
and hence it should be placed in a different method instead of merging it the add_signup_topics&lt;br /&gt;
 &lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
    load_add_signup_topics(params[:id])&lt;br /&gt;
  if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
     &lt;br /&gt;
   &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#Function call to set up due dates&lt;br /&gt;
      assignment_due_date&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
   #Render a view different from the add_sign_up.html.erb  , so rendering a view for staggered deadlines.&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assignment_due_date&lt;br /&gt;
     #below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==Case 3 : Modularize Code in application.rb==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
In the assignment.rb model, there exists one method(check_condition) which checks whether review, meta-review, etc are allowed or not. This method makes database calls to TopicDeadline table, DueDate and DeadlineType tables. Following is the code which was existing before the changes were made. It has the logic to find the nearest due date that hasn't passed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     drop_topic_deadline_id = DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      &lt;br /&gt;
      if topic_id&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                   topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
      else&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      next_due_date = DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
===After changes===&lt;br /&gt;
The database queries have been moved to their respective models. The queries to TopicDeadline table, DueDate table and DeadlineType table have been moved to their models. Below is the new code in assignments.rb model which calls TopicDeadline.rb, DueDate.rb and DeadlineType.rb respectively for the queries in their tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt; model&lt;br /&gt;
&lt;br /&gt;
 if self.staggered_deadline?&lt;br /&gt;
   next_due_date = TopicDeadline.find_next_due_date(topic_id,self.id)&lt;br /&gt;
 else&lt;br /&gt;
   next_due_date = DueDate.find_next_due_date(self.id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; defined in &amp;lt;b&amp;gt;topic_deadline.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
 def self.find_next_due_date(topic_id,assignment_id)&lt;br /&gt;
    drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
    if topic_id&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    else&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         assignment_id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;due_date.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_next_due_date(assignment_id&lt;br /&gt;
   drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
   DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                assignment_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_drop_topic_deadline_id&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;deadline_type.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_drop_topic_deadline_id()&lt;br /&gt;
   DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
== Case 4 : DeadCode Elimination in  sign_up_sheet_controller.rb ==&lt;br /&gt;
&lt;br /&gt;
The local variables topic_set and topic under the staggered deadline check statement were never used in the entire scope of the project , it introduced code smells. So it was checked if there was any reference to this code, and upon discovering it was not used anywhere, we decided to eliminate this [http://en.wikipedia.org/wiki/Dead_code_elimination deadcode].&lt;br /&gt;
 &lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      topic_set = Array.new&lt;br /&gt;
      topic = @sign_up_topic.id&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
 &lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role or super user's role.&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and hover over the assignment “StaggeredDeadlines_Refactoring”.&lt;br /&gt;
&lt;br /&gt;
2. Click on “New Topic”.&lt;br /&gt;
&lt;br /&gt;
3. Enter the details of the topic you want to create. Create at least 2 topics for better analysis of the project.&lt;br /&gt;
&lt;br /&gt;
[[File:AddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90737</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90737"/>
		<updated>2014-10-29T20:08:30Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Adding Edit/Delete functionality to topics tab */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
= Project Resources =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itsmylifesoham/expertiza GitHub Project Repository]&lt;br /&gt;
&lt;br /&gt;
[http://152.46.18.5:3000/ VCL IP Address]&lt;br /&gt;
&lt;br /&gt;
[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki]&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Refactoring view code into relevant views&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    ... &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Similarly the method call is re-factored in various views.&lt;br /&gt;
For instance, for view _assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;% &amp;lt;b&amp;gt;if @assignment.staggered_deadline == true&amp;lt;/b&amp;gt; %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics_staggered'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Method Extraction  ==&lt;br /&gt;
&lt;br /&gt;
Improved readability by [http://sourcemaking.com/refactoring/extract-method extracting] two separate functionalities from the same method into separate methods with appropriate naming convention and responsibilities.&lt;br /&gt;
&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
The add_signup_topics calculated due dates for separate topics for a Staggered assignment with individual Topic deadlines.&lt;br /&gt;
&lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
   load_add_signup_topics(params[:id])&lt;br /&gt;
   if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
      &lt;br /&gt;
     &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
      #Render a view different for staggered deadlines assignment from the add_sign_up.html.erb&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The logic to calculate due_dates was moved to a separate method called assignment_due_date , as this is only valid for staggered assignments   &lt;br /&gt;
and hence it should be placed in a different method instead of merging it the add_signup_topics&lt;br /&gt;
 &lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
    load_add_signup_topics(params[:id])&lt;br /&gt;
  if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
     &lt;br /&gt;
   &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#Function call to set up due dates&lt;br /&gt;
      assignment_due_date&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
   #Render a view different from the add_sign_up.html.erb  , so rendering a view for staggered deadlines.&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assignment_due_date&lt;br /&gt;
     #below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==Case 3 : Modularize Code in application.rb==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
In the assignment.rb model, there exists one method(check_condition) which checks whether review, meta-review, etc are allowed or not. This method makes database calls to TopicDeadline table, DueDate and DeadlineType tables. Following is the code which was existing before the changes were made. It has the logic to find the nearest due date that hasn't passed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     drop_topic_deadline_id = DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      &lt;br /&gt;
      if topic_id&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                   topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
      else&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      next_due_date = DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
===After changes===&lt;br /&gt;
The database queries have been moved to their respective models. The queries to TopicDeadline table, DueDate table and DeadlineType table have been moved to their models. Below is the new code in assignments.rb model which calls TopicDeadline.rb, DueDate.rb and DeadlineType.rb respectively for the queries in their tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt; model&lt;br /&gt;
&lt;br /&gt;
 if self.staggered_deadline?&lt;br /&gt;
   next_due_date = TopicDeadline.find_next_due_date(topic_id,self.id)&lt;br /&gt;
 else&lt;br /&gt;
   next_due_date = DueDate.find_next_due_date(self.id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; defined in &amp;lt;b&amp;gt;topic_deadline.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
 def self.find_next_due_date(topic_id,assignment_id)&lt;br /&gt;
    drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
    if topic_id&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    else&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         assignment_id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;due_date.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_next_due_date(assignment_id&lt;br /&gt;
   drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
   DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                assignment_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_drop_topic_deadline_id&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;deadline_type.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_drop_topic_deadline_id()&lt;br /&gt;
   DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
== Case 4 : DeadCode Elimination in  sign_up_sheet_controller.rb ==&lt;br /&gt;
&lt;br /&gt;
The local variables topic_set and topic under the staggered deadline check statement were never used in the entire scope of the project , it introduced code smells. So it was checked if there was any reference to this code, and upon discovering it was not used anywhere, we decided to eliminate this [http://en.wikipedia.org/wiki/Dead_code_elimination deadcode].&lt;br /&gt;
 &lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      topic_set = Array.new&lt;br /&gt;
      topic = @sign_up_topic.id&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
 &lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role or super user's role.&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and hover over the assignment “StaggeredDeadlines_Refactoring”.&lt;br /&gt;
&lt;br /&gt;
2. Click on “New Topic”.&lt;br /&gt;
&lt;br /&gt;
3. Enter the details of the topic you want to create. Create at least 2 topics for better analysis of the project.&lt;br /&gt;
&lt;br /&gt;
[[File:AddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90735</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90735"/>
		<updated>2014-10-29T20:07:34Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Adding Edit/Delete links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
= Project Resources =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itsmylifesoham/expertiza GitHub Project Repository]&lt;br /&gt;
&lt;br /&gt;
[http://152.46.18.5:3000/ VCL IP Address]&lt;br /&gt;
&lt;br /&gt;
[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki]&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Refactoring view code into relevant views&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete functionality to topics tab===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def redirect_to_sign_up(assignment_id)&lt;br /&gt;
    assignment = Assignment.find(assignment_id)&lt;br /&gt;
    redirect_to :action =&amp;gt; 'add_signup_topics', :id =&amp;gt; assignment_id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Similarly the method call is re-factored in various views.&lt;br /&gt;
For instance, for view _assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;% &amp;lt;b&amp;gt;if @assignment.staggered_deadline == true&amp;lt;/b&amp;gt; %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics_staggered'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Method Extraction  ==&lt;br /&gt;
&lt;br /&gt;
Improved readability by [http://sourcemaking.com/refactoring/extract-method extracting] two separate functionalities from the same method into separate methods with appropriate naming convention and responsibilities.&lt;br /&gt;
&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
The add_signup_topics calculated due dates for separate topics for a Staggered assignment with individual Topic deadlines.&lt;br /&gt;
&lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
   load_add_signup_topics(params[:id])&lt;br /&gt;
   if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
      &lt;br /&gt;
     &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
      #Render a view different for staggered deadlines assignment from the add_sign_up.html.erb&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The logic to calculate due_dates was moved to a separate method called assignment_due_date , as this is only valid for staggered assignments   &lt;br /&gt;
and hence it should be placed in a different method instead of merging it the add_signup_topics&lt;br /&gt;
 &lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
    load_add_signup_topics(params[:id])&lt;br /&gt;
  if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
     &lt;br /&gt;
   &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#Function call to set up due dates&lt;br /&gt;
      assignment_due_date&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
   #Render a view different from the add_sign_up.html.erb  , so rendering a view for staggered deadlines.&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assignment_due_date&lt;br /&gt;
     #below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==Case 3 : Modularize Code in application.rb==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
In the assignment.rb model, there exists one method(check_condition) which checks whether review, meta-review, etc are allowed or not. This method makes database calls to TopicDeadline table, DueDate and DeadlineType tables. Following is the code which was existing before the changes were made. It has the logic to find the nearest due date that hasn't passed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     drop_topic_deadline_id = DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      &lt;br /&gt;
      if topic_id&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                   topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
      else&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      next_due_date = DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
===After changes===&lt;br /&gt;
The database queries have been moved to their respective models. The queries to TopicDeadline table, DueDate table and DeadlineType table have been moved to their models. Below is the new code in assignments.rb model which calls TopicDeadline.rb, DueDate.rb and DeadlineType.rb respectively for the queries in their tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt; model&lt;br /&gt;
&lt;br /&gt;
 if self.staggered_deadline?&lt;br /&gt;
   next_due_date = TopicDeadline.find_next_due_date(topic_id,self.id)&lt;br /&gt;
 else&lt;br /&gt;
   next_due_date = DueDate.find_next_due_date(self.id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; defined in &amp;lt;b&amp;gt;topic_deadline.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
 def self.find_next_due_date(topic_id,assignment_id)&lt;br /&gt;
    drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
    if topic_id&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    else&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         assignment_id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;due_date.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_next_due_date(assignment_id&lt;br /&gt;
   drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
   DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                assignment_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_drop_topic_deadline_id&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;deadline_type.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_drop_topic_deadline_id()&lt;br /&gt;
   DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
== Case 4 : DeadCode Elimination in  sign_up_sheet_controller.rb ==&lt;br /&gt;
&lt;br /&gt;
The local variables topic_set and topic under the staggered deadline check statement were never used in the entire scope of the project , it introduced code smells. So it was checked if there was any reference to this code, and upon discovering it was not used anywhere, we decided to eliminate this [http://en.wikipedia.org/wiki/Dead_code_elimination deadcode].&lt;br /&gt;
 &lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      topic_set = Array.new&lt;br /&gt;
      topic = @sign_up_topic.id&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
 &lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role or super user's role.&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and hover over the assignment “StaggeredDeadlines_Refactoring”.&lt;br /&gt;
&lt;br /&gt;
2. Click on “New Topic”.&lt;br /&gt;
&lt;br /&gt;
3. Enter the details of the topic you want to create. Create at least 2 topics for better analysis of the project.&lt;br /&gt;
&lt;br /&gt;
[[File:AddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90734</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90734"/>
		<updated>2014-10-29T20:06:45Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Current Scenario */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
= Project Resources =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itsmylifesoham/expertiza GitHub Project Repository]&lt;br /&gt;
&lt;br /&gt;
[http://152.46.18.5:3000/ VCL IP Address]&lt;br /&gt;
&lt;br /&gt;
[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki]&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Removing duplicate _add_signup_topics partials===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Refactoring view code into relevant views&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete links===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def redirect_to_sign_up(assignment_id)&lt;br /&gt;
    assignment = Assignment.find(assignment_id)&lt;br /&gt;
    redirect_to :action =&amp;gt; 'add_signup_topics', :id =&amp;gt; assignment_id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Similarly the method call is re-factored in various views.&lt;br /&gt;
For instance, for view _assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;% &amp;lt;b&amp;gt;if @assignment.staggered_deadline == true&amp;lt;/b&amp;gt; %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics_staggered'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Method Extraction  ==&lt;br /&gt;
&lt;br /&gt;
Improved readability by [http://sourcemaking.com/refactoring/extract-method extracting] two separate functionalities from the same method into separate methods with appropriate naming convention and responsibilities.&lt;br /&gt;
&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
The add_signup_topics calculated due dates for separate topics for a Staggered assignment with individual Topic deadlines.&lt;br /&gt;
&lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
   load_add_signup_topics(params[:id])&lt;br /&gt;
   if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
      &lt;br /&gt;
     &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
      #Render a view different for staggered deadlines assignment from the add_sign_up.html.erb&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The logic to calculate due_dates was moved to a separate method called assignment_due_date , as this is only valid for staggered assignments   &lt;br /&gt;
and hence it should be placed in a different method instead of merging it the add_signup_topics&lt;br /&gt;
 &lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
    load_add_signup_topics(params[:id])&lt;br /&gt;
  if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
     &lt;br /&gt;
   &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#Function call to set up due dates&lt;br /&gt;
      assignment_due_date&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
   #Render a view different from the add_sign_up.html.erb  , so rendering a view for staggered deadlines.&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assignment_due_date&lt;br /&gt;
     #below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==Case 3 : Modularize Code in application.rb==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
In the assignment.rb model, there exists one method(check_condition) which checks whether review, meta-review, etc are allowed or not. This method makes database calls to TopicDeadline table, DueDate and DeadlineType tables. Following is the code which was existing before the changes were made. It has the logic to find the nearest due date that hasn't passed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     drop_topic_deadline_id = DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      &lt;br /&gt;
      if topic_id&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                   topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
      else&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      next_due_date = DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
===After changes===&lt;br /&gt;
The database queries have been moved to their respective models. The queries to TopicDeadline table, DueDate table and DeadlineType table have been moved to their models. Below is the new code in assignments.rb model which calls TopicDeadline.rb, DueDate.rb and DeadlineType.rb respectively for the queries in their tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt; model&lt;br /&gt;
&lt;br /&gt;
 if self.staggered_deadline?&lt;br /&gt;
   next_due_date = TopicDeadline.find_next_due_date(topic_id,self.id)&lt;br /&gt;
 else&lt;br /&gt;
   next_due_date = DueDate.find_next_due_date(self.id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; defined in &amp;lt;b&amp;gt;topic_deadline.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
 def self.find_next_due_date(topic_id,assignment_id)&lt;br /&gt;
    drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
    if topic_id&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    else&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         assignment_id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;due_date.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_next_due_date(assignment_id&lt;br /&gt;
   drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
   DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                assignment_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_drop_topic_deadline_id&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;deadline_type.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_drop_topic_deadline_id()&lt;br /&gt;
   DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
== Case 4 : DeadCode Elimination in  sign_up_sheet_controller.rb ==&lt;br /&gt;
&lt;br /&gt;
The local variables topic_set and topic under the staggered deadline check statement were never used in the entire scope of the project , it introduced code smells. So it was checked if there was any reference to this code, and upon discovering it was not used anywhere, we decided to eliminate this [http://en.wikipedia.org/wiki/Dead_code_elimination deadcode].&lt;br /&gt;
 &lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      topic_set = Array.new&lt;br /&gt;
      topic = @sign_up_topic.id&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
 &lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role or super user's role.&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and hover over the assignment “StaggeredDeadlines_Refactoring”.&lt;br /&gt;
&lt;br /&gt;
2. Click on “New Topic”.&lt;br /&gt;
&lt;br /&gt;
3. Enter the details of the topic you want to create. Create at least 2 topics for better analysis of the project.&lt;br /&gt;
&lt;br /&gt;
[[File:AddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90733</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90733"/>
		<updated>2014-10-29T20:05:59Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
= Project Resources =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itsmylifesoham/expertiza GitHub Project Repository]&lt;br /&gt;
&lt;br /&gt;
[http://152.46.18.5:3000/ VCL IP Address]&lt;br /&gt;
&lt;br /&gt;
[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki]&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController ==&lt;br /&gt;
&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Refactoring view code into relevant views&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
There were no edit/delete links to edit/delete a topic in the instructor view. These had to be conditionally added based on the role of the currently logged in user. This was to prevent students from editing/deleting topics and to keep instructors from signing up for a topic. This was implemented as follows.&lt;br /&gt;
&lt;br /&gt;
===Adding Edit/Delete links===&lt;br /&gt;
&lt;br /&gt;
The current expertiza project had two views to display the Actions column in the topics table. These were _reserve_topics.html.erb and _actions.html. The first one was displaying the signup button for the student and the latter was displaying the bookmarks and rendering the _reserve_topics.html.erb after the bookmarks. On top of this we had to add the edit/delete links for the instructor. A refactor was called for. We decided to create a _all_actions.html.erb partial which had the responsibility to display the relevant actions depending upon the role of the currently logged in user. This helped us remove the separate partial to render actions pertaining to a student, namely _reserve_topics.html.erb . Also the _actions.html.erb only took care of displaying the bookmark links rather than dealing with both bookmarks and actions. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;partial_view:_all_actions,html.erb&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% if ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator'].include? current_user_role?.name %&amp;gt;&lt;br /&gt;
    &amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('edit_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Edit Topic', :align =&amp;gt; 'middle'), :controller=&amp;gt;'sign_up_sheet', :action=&amp;gt; 'edit', :id =&amp;gt; topic.id %&amp;gt;&lt;br /&gt;
      &amp;lt;%= link_to image_tag('delete_icon.png', :border =&amp;gt; 0, :title =&amp;gt; 'Delete Topic', :align =&amp;gt; 'middle'), sign_up_sheet_path(topic.id), method: :delete, data: {confirm: 'Are you sure?'} %&amp;gt;&lt;br /&gt;
&amp;lt;%elsif @show_actions %&amp;gt; &lt;br /&gt;
    #Render signup button for student here. The @show_actions will be true if this partial is navigated from the SignupSheetController which is accessible only to students.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def redirect_to_sign_up(assignment_id)&lt;br /&gt;
    assignment = Assignment.find(assignment_id)&lt;br /&gt;
    redirect_to :action =&amp;gt; 'add_signup_topics', :id =&amp;gt; assignment_id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Similarly the method call is re-factored in various views.&lt;br /&gt;
For instance, for view _assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;% &amp;lt;b&amp;gt;if @assignment.staggered_deadline == true&amp;lt;/b&amp;gt; %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics_staggered'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Method Extraction  ==&lt;br /&gt;
&lt;br /&gt;
Improved readability by [http://sourcemaking.com/refactoring/extract-method extracting] two separate functionalities from the same method into separate methods with appropriate naming convention and responsibilities.&lt;br /&gt;
&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
The add_signup_topics calculated due dates for separate topics for a Staggered assignment with individual Topic deadlines.&lt;br /&gt;
&lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
   load_add_signup_topics(params[:id])&lt;br /&gt;
   if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
      &lt;br /&gt;
     &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
      #Render a view different for staggered deadlines assignment from the add_sign_up.html.erb&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The logic to calculate due_dates was moved to a separate method called assignment_due_date , as this is only valid for staggered assignments   &lt;br /&gt;
and hence it should be placed in a different method instead of merging it the add_signup_topics&lt;br /&gt;
 &lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
    load_add_signup_topics(params[:id])&lt;br /&gt;
  if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
     &lt;br /&gt;
   &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#Function call to set up due dates&lt;br /&gt;
      assignment_due_date&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
   #Render a view different from the add_sign_up.html.erb  , so rendering a view for staggered deadlines.&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assignment_due_date&lt;br /&gt;
     #below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==Case 3 : Modularize Code in application.rb==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
In the assignment.rb model, there exists one method(check_condition) which checks whether review, meta-review, etc are allowed or not. This method makes database calls to TopicDeadline table, DueDate and DeadlineType tables. Following is the code which was existing before the changes were made. It has the logic to find the nearest due date that hasn't passed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     drop_topic_deadline_id = DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      &lt;br /&gt;
      if topic_id&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                   topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
      else&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      next_due_date = DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
===After changes===&lt;br /&gt;
The database queries have been moved to their respective models. The queries to TopicDeadline table, DueDate table and DeadlineType table have been moved to their models. Below is the new code in assignments.rb model which calls TopicDeadline.rb, DueDate.rb and DeadlineType.rb respectively for the queries in their tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt; model&lt;br /&gt;
&lt;br /&gt;
 if self.staggered_deadline?&lt;br /&gt;
   next_due_date = TopicDeadline.find_next_due_date(topic_id,self.id)&lt;br /&gt;
 else&lt;br /&gt;
   next_due_date = DueDate.find_next_due_date(self.id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; defined in &amp;lt;b&amp;gt;topic_deadline.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
 def self.find_next_due_date(topic_id,assignment_id)&lt;br /&gt;
    drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
    if topic_id&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    else&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         assignment_id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;due_date.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_next_due_date(assignment_id&lt;br /&gt;
   drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
   DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                assignment_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_drop_topic_deadline_id&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;deadline_type.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_drop_topic_deadline_id()&lt;br /&gt;
   DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
== Case 4 : DeadCode Elimination in  sign_up_sheet_controller.rb ==&lt;br /&gt;
&lt;br /&gt;
The local variables topic_set and topic under the staggered deadline check statement were never used in the entire scope of the project , it introduced code smells. So it was checked if there was any reference to this code, and upon discovering it was not used anywhere, we decided to eliminate this [http://en.wikipedia.org/wiki/Dead_code_elimination deadcode].&lt;br /&gt;
 &lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      topic_set = Array.new&lt;br /&gt;
      topic = @sign_up_topic.id&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
 &lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role or super user's role.&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and hover over the assignment “StaggeredDeadlines_Refactoring”.&lt;br /&gt;
&lt;br /&gt;
2. Click on “New Topic”.&lt;br /&gt;
&lt;br /&gt;
3. Enter the details of the topic you want to create. Create at least 2 topics for better analysis of the project.&lt;br /&gt;
&lt;br /&gt;
[[File:AddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90718</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90718"/>
		<updated>2014-10-29T19:48:53Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
= Project Resources =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itsmylifesoham/expertiza GitHub Project Repository]&lt;br /&gt;
&lt;br /&gt;
[http://152.46.18.5:3000/ VCL IP Address]&lt;br /&gt;
&lt;br /&gt;
[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki]&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController to use same views ==&lt;br /&gt;
&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Single method call&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
At several places in the project, there was separate method call based on staggered and non-staggered assignments. We have made a single method call and condition check in various files ,for type of assignment, has been removed as part of re-factoring.&lt;br /&gt;
&lt;br /&gt;
 def redirect_to_sign_up(assignment_id)&lt;br /&gt;
    assignment = Assignment.find(assignment_id)&lt;br /&gt;
    redirect_to :action =&amp;gt; 'add_signup_topics', :id =&amp;gt; assignment_id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Similarly the method call is re-factored in various views.&lt;br /&gt;
For instance, for view _assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;% &amp;lt;b&amp;gt;if @assignment.staggered_deadline == true&amp;lt;/b&amp;gt; %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics_staggered'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Method Extraction  ==&lt;br /&gt;
&lt;br /&gt;
Improved readability by [http://sourcemaking.com/refactoring/extract-method extracting] two separate functionalities from the same method into separate methods with appropriate naming convention and responsibilities.&lt;br /&gt;
&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
The add_signup_topics calculated due dates for separate topics for a Staggered assignment with individual Topic deadlines.&lt;br /&gt;
&lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
   load_add_signup_topics(params[:id])&lt;br /&gt;
   if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
      &lt;br /&gt;
     &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
      #Render a view different for staggered deadlines assignment from the add_sign_up.html.erb&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The logic to calculate due_dates was moved to a separate method called assignment_due_date , as this is only valid for staggered assignments   &lt;br /&gt;
and hence it should be placed in a different method instead of merging it the add_signup_topics&lt;br /&gt;
 &lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
    load_add_signup_topics(params[:id])&lt;br /&gt;
  if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
     &lt;br /&gt;
   &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#Function call to set up due dates&lt;br /&gt;
      assignment_due_date&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
   #Render a view different from the add_sign_up.html.erb  , so rendering a view for staggered deadlines.&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assignment_due_date&lt;br /&gt;
     #below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==Case 3 : Modularize Code in application.rb==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
In the assignment.rb model, there exists one method(check_condition) which checks whether review, meta-review, etc are allowed or not. This method makes database calls to TopicDeadline table, DueDate and DeadlineType tables. Following is the code which was existing before the changes were made. It has the logic to find the nearest due date that hasn't passed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     drop_topic_deadline_id = DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      &lt;br /&gt;
      if topic_id&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                   topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
      else&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      next_due_date = DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
===After changes===&lt;br /&gt;
The database queries have been moved to their respective models. The queries to TopicDeadline table, DueDate table and DeadlineType table have been moved to their models. Below is the new code in assignments.rb model which calls TopicDeadline.rb, DueDate.rb and DeadlineType.rb respectively for the queries in their tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt; model&lt;br /&gt;
&lt;br /&gt;
 if self.staggered_deadline?&lt;br /&gt;
   next_due_date = TopicDeadline.find_next_due_date(topic_id,self.id)&lt;br /&gt;
 else&lt;br /&gt;
   next_due_date = DueDate.find_next_due_date(self.id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; defined in &amp;lt;b&amp;gt;topic_deadline.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
 def self.find_next_due_date(topic_id,assignment_id)&lt;br /&gt;
    drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
    if topic_id&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    else&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         assignment_id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;due_date.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_next_due_date(assignment_id&lt;br /&gt;
   drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
   DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                assignment_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_drop_topic_deadline_id&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;deadline_type.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_drop_topic_deadline_id()&lt;br /&gt;
   DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
== Case 4 : DeadCode Elimination in  sign_up_sheet_controller.rb ==&lt;br /&gt;
&lt;br /&gt;
The local variables topic_set and topic under the staggered deadline check statement were never used in the entire scope of the project , it introduced code smells. So it was checked if there was any reference to this code, and upon discovering it was not used anywhere, we decided to eliminate this [http://en.wikipedia.org/wiki/Dead_code_elimination deadcode].&lt;br /&gt;
 &lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      topic_set = Array.new&lt;br /&gt;
      topic = @sign_up_topic.id&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
 &lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role or super user's role.&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and hover over the assignment “StaggeredDeadlines_Refactoring”.&lt;br /&gt;
&lt;br /&gt;
2. Click on “New Topic”.&lt;br /&gt;
&lt;br /&gt;
3. Enter the details of the topic you want to create. Create at least 2 topics for better analysis of the project.&lt;br /&gt;
&lt;br /&gt;
[[File:AddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90716</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90716"/>
		<updated>2014-10-29T19:47:31Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
= Project Resources =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itsmylifesoham/expertiza GitHub Project Repository]&lt;br /&gt;
&lt;br /&gt;
[http://152.46.18.5:3000/ VCL IP Address]&lt;br /&gt;
&lt;br /&gt;
[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki]&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring the AssignmentsController and SignupSheetController to use same views ==&lt;br /&gt;
&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
The AssignmentsController displayed topics to the instructor while he was editing an assignment. It used _add_signup_topics.html.erb partial to render topics under the topics tab. The SignupSheetController displayed topics to a student who wanted to view signup topics under an assignment. It was found that it had its own copy namely _add_signup_topcis.html.erb to display topics to the student. We wanted to have these two controllers use the same views to render the same thing which was list of topics under an assignment. We made the AssignmentsController reuse the _add_signup_topcis.html.erb partial under the SignupSheetController.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;view:assignments/edit.html.erb&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This view contains all the tabs to display like general,rubrics,review_strategy, topics which are related to the selected assignment. tabs-5 is the topics tab which we are interested in.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/add_signup_topics' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-3&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/review_strategy' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render 'assignments/edit/due_dates' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
   &amp;lt;div id=&amp;quot;tabs-5&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;%= render '/sign_up_sheet/add_signup_topcis.html' %&amp;gt;&lt;br /&gt;
   &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;method:add_signup_topics&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
It is similar to the above function except that all the topics and review/submission rounds have the similar deadlines.&lt;br /&gt;
  def add_signup_topics&lt;br /&gt;
    load_add_signup_topics(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Conditional call&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We had to make conditional check every time the function is called for the assignment type. For instance, below method redirects to the /add_signup_topics or the /add_signup_topics_staggered page depending on assignment type &lt;br /&gt;
 def redirect_to_sign_up(assignment_id)&lt;br /&gt;
    assignment = Assignment.find(assignment_id)&lt;br /&gt;
    if assignment.staggered_deadline == true&lt;br /&gt;
      redirect_to :action =&amp;gt; 'add_signup_topics_staggered', :id =&amp;gt; assignment_id&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :action =&amp;gt; 'add_signup_topics', :id =&amp;gt; assignment_id&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
    load_add_signup_topics(params[:id])&lt;br /&gt;
    if @assignment.staggered_deadline ==true&lt;br /&gt;
       ....&lt;br /&gt;
       &lt;br /&gt;
       #below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
       @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
       ....&lt;br /&gt;
       &lt;br /&gt;
       #Render a view different for staggered deadlines assignment from the add_sign_up.html.erb&lt;br /&gt;
       render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Single method call&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
At several places in the project, there was separate method call based on staggered and non-staggered assignments. We have made a single method call and condition check in various files ,for type of assignment, has been removed as part of re-factoring.&lt;br /&gt;
&lt;br /&gt;
 def redirect_to_sign_up(assignment_id)&lt;br /&gt;
    assignment = Assignment.find(assignment_id)&lt;br /&gt;
    redirect_to :action =&amp;gt; 'add_signup_topics', :id =&amp;gt; assignment_id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Similarly the method call is re-factored in various views.&lt;br /&gt;
For instance, for view _assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;% &amp;lt;b&amp;gt;if @assignment.staggered_deadline == true&amp;lt;/b&amp;gt; %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics_staggered'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Method Extraction  ==&lt;br /&gt;
&lt;br /&gt;
Improved readability by [http://sourcemaking.com/refactoring/extract-method extracting] two separate functionalities from the same method into separate methods with appropriate naming convention and responsibilities.&lt;br /&gt;
&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
The add_signup_topics calculated due dates for separate topics for a Staggered assignment with individual Topic deadlines.&lt;br /&gt;
&lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
   load_add_signup_topics(params[:id])&lt;br /&gt;
   if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
      &lt;br /&gt;
     &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
      #Render a view different for staggered deadlines assignment from the add_sign_up.html.erb&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The logic to calculate due_dates was moved to a separate method called assignment_due_date , as this is only valid for staggered assignments   &lt;br /&gt;
and hence it should be placed in a different method instead of merging it the add_signup_topics&lt;br /&gt;
 &lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
    load_add_signup_topics(params[:id])&lt;br /&gt;
  if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
     &lt;br /&gt;
   &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#Function call to set up due dates&lt;br /&gt;
      assignment_due_date&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
   #Render a view different from the add_sign_up.html.erb  , so rendering a view for staggered deadlines.&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assignment_due_date&lt;br /&gt;
     #below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==Case 3 : Modularize Code in application.rb==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
In the assignment.rb model, there exists one method(check_condition) which checks whether review, meta-review, etc are allowed or not. This method makes database calls to TopicDeadline table, DueDate and DeadlineType tables. Following is the code which was existing before the changes were made. It has the logic to find the nearest due date that hasn't passed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     drop_topic_deadline_id = DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      &lt;br /&gt;
      if topic_id&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                   topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
      else&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      next_due_date = DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
===After changes===&lt;br /&gt;
The database queries have been moved to their respective models. The queries to TopicDeadline table, DueDate table and DeadlineType table have been moved to their models. Below is the new code in assignments.rb model which calls TopicDeadline.rb, DueDate.rb and DeadlineType.rb respectively for the queries in their tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt; model&lt;br /&gt;
&lt;br /&gt;
 if self.staggered_deadline?&lt;br /&gt;
   next_due_date = TopicDeadline.find_next_due_date(topic_id,self.id)&lt;br /&gt;
 else&lt;br /&gt;
   next_due_date = DueDate.find_next_due_date(self.id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; defined in &amp;lt;b&amp;gt;topic_deadline.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
 def self.find_next_due_date(topic_id,assignment_id)&lt;br /&gt;
    drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
    if topic_id&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    else&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         assignment_id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;due_date.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_next_due_date(assignment_id&lt;br /&gt;
   drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
   DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                assignment_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_drop_topic_deadline_id&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;deadline_type.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_drop_topic_deadline_id()&lt;br /&gt;
   DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
== Case 4 : DeadCode Elimination in  sign_up_sheet_controller.rb ==&lt;br /&gt;
&lt;br /&gt;
The local variables topic_set and topic under the staggered deadline check statement were never used in the entire scope of the project , it introduced code smells. So it was checked if there was any reference to this code, and upon discovering it was not used anywhere, we decided to eliminate this [http://en.wikipedia.org/wiki/Dead_code_elimination deadcode].&lt;br /&gt;
 &lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      topic_set = Array.new&lt;br /&gt;
      topic = @sign_up_topic.id&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
 &lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role or super user's role.&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and hover over the assignment “StaggeredDeadlines_Refactoring”.&lt;br /&gt;
&lt;br /&gt;
2. Click on “New Topic”.&lt;br /&gt;
&lt;br /&gt;
3. Enter the details of the topic you want to create. Create at least 2 topics for better analysis of the project.&lt;br /&gt;
&lt;br /&gt;
[[File:AddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90690</id>
		<title>CSC/ECE 517 Fall 2014/oss E1453 syy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1453_syy&amp;diff=90690"/>
		<updated>2014-10-29T19:32:42Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: Created page with &amp;quot;'''E1453. Refactoring AssignmentsController'''  This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController a...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1453. Refactoring AssignmentsController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the AssignmentsController as well as adding some missing functionality related to topics within an assignment.&lt;br /&gt;
&lt;br /&gt;
'''Introduction to Expertiza'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using Ruby on Rails platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large. &lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
= Project Resources =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itsmylifesoham/expertiza GitHub Project Repository]&lt;br /&gt;
&lt;br /&gt;
[http://152.46.18.5:3000/ VCL IP Address]&lt;br /&gt;
&lt;br /&gt;
[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki]&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
Currently the topics tab is not usable to the instructor when he is editing a current assignment or creating a new one. This functionality is necessary as it enables the instructor to create/delete/edit/view topics present under the selected assignment. Currently, the instructor achieves this using the pop-up menu that appears adjacent every assignment on the page that lists all the assignments. We were required to implement the topics tab.&lt;br /&gt;
&lt;br /&gt;
The functionality to display the topics under an assignment is duplicated between the AssignmentController views and the SignupSheetController views. Both the instructor and the student can view the topics by selecting an assignment and we were required to remove this duplication in the views.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code Cases =&lt;br /&gt;
&lt;br /&gt;
== Case 1 : Refactoring in sign_up_sheet_controller.rb ==&lt;br /&gt;
&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
Different method definitions for setting up staggered and non-staggered assignment sign up sheet.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;method:add_signup_topics_staggered&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This method lists all the available topics for an assignment and allows admin to set due dates for assignment.Staggered means that different topics can have different deadlines.&lt;br /&gt;
  def add_signup_topics_staggered&lt;br /&gt;
    load_add_signup_topics(params[:id])&lt;br /&gt;
    ....&lt;br /&gt;
    &lt;br /&gt;
    #below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
    @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
    ....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;method:add_signup_topics&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
It is similar to the above function except that all the topics and review/submission rounds have the similar deadlines.&lt;br /&gt;
  def add_signup_topics&lt;br /&gt;
    load_add_signup_topics(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Conditional call&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We had to make conditional check every time the function is called for the assignment type. For instance, below method redirects to the /add_signup_topics or the /add_signup_topics_staggered page depending on assignment type &lt;br /&gt;
 def redirect_to_sign_up(assignment_id)&lt;br /&gt;
    assignment = Assignment.find(assignment_id)&lt;br /&gt;
    if assignment.staggered_deadline == true&lt;br /&gt;
      redirect_to :action =&amp;gt; 'add_signup_topics_staggered', :id =&amp;gt; assignment_id&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :action =&amp;gt; 'add_signup_topics', :id =&amp;gt; assignment_id&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
We have redundant code in two methods so we merged add_signup_topics_staggered and add_signup_topics into add_signup_topics. The action calls single method for both type of assignments and renders views based on condition of staggered or non-staggered assignment.&lt;br /&gt;
&lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
    load_add_signup_topics(params[:id])&lt;br /&gt;
    if @assignment.staggered_deadline ==true&lt;br /&gt;
       ....&lt;br /&gt;
       &lt;br /&gt;
       #below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
       @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
       ....&lt;br /&gt;
       &lt;br /&gt;
       #Render a view different for staggered deadlines assignment from the add_sign_up.html.erb&lt;br /&gt;
       render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Single method call&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
At several places in the project, there was separate method call based on staggered and non-staggered assignments. We have made a single method call and condition check in various files ,for type of assignment, has been removed as part of re-factoring.&lt;br /&gt;
&lt;br /&gt;
 def redirect_to_sign_up(assignment_id)&lt;br /&gt;
    assignment = Assignment.find(assignment_id)&lt;br /&gt;
    redirect_to :action =&amp;gt; 'add_signup_topics', :id =&amp;gt; assignment_id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Similarly the method call is re-factored in various views.&lt;br /&gt;
For instance, for view _assignments_actions.html.erb&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;% &amp;lt;b&amp;gt;if @assignment.staggered_deadline == true&amp;lt;/b&amp;gt; %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics_staggered'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% else %&amp;gt;&lt;br /&gt;
    &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
 &amp;lt;% end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Changes&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to image_tag('/images/tree_view/edit-signup-sheet-24.png', :title =&amp;gt; 'Edit signup sheet'), &lt;br /&gt;
      {:controller =&amp;gt; 'sign_up_sheet', &amp;lt;b&amp;gt;:action =&amp;gt; 'add_signup_topics'&amp;lt;/b&amp;gt;, :id =&amp;gt; node.node_object_id}, &lt;br /&gt;
      {:title =&amp;gt; 'Edit signup sheet'} %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Case 2 : Method Extraction  ==&lt;br /&gt;
&lt;br /&gt;
Improved readability by [http://sourcemaking.com/refactoring/extract-method extracting] two separate functionalities from the same method into separate methods with appropriate naming convention and responsibilities.&lt;br /&gt;
&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
The add_signup_topics calculated due dates for separate topics for a Staggered assignment with individual Topic deadlines.&lt;br /&gt;
&lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
   load_add_signup_topics(params[:id])&lt;br /&gt;
   if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
      &lt;br /&gt;
     &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
      #Render a view different for staggered deadlines assignment from the add_sign_up.html.erb&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
&lt;br /&gt;
The logic to calculate due_dates was moved to a separate method called assignment_due_date , as this is only valid for staggered assignments   &lt;br /&gt;
and hence it should be placed in a different method instead of merging it the add_signup_topics&lt;br /&gt;
 &lt;br /&gt;
 def add_signup_topics&lt;br /&gt;
    load_add_signup_topics(params[:id])&lt;br /&gt;
  if @assignment.staggered_deadline ==true&lt;br /&gt;
      @review_rounds = Assignment.find(params[:id]).get_review_rounds&lt;br /&gt;
      @topics = SignUpTopic.find_all_by_assignment_id(params[:id])&lt;br /&gt;
     &lt;br /&gt;
   &amp;lt;b&amp;gt;&amp;lt;i&amp;gt;#Function call to set up due dates&lt;br /&gt;
      assignment_due_date&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
   #Render a view different from the add_sign_up.html.erb  , so rendering a view for staggered deadlines.&lt;br /&gt;
      render &amp;quot;add_signup_topics_staggered&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assignment_due_date&lt;br /&gt;
     #below functionality finds allows to set due dates for topics of assignment&lt;br /&gt;
      @duedates = SignUpTopic.find_by_sql(&amp;quot;SELECT s.id as topic_id FROM sign_up_topics s WHERE s.assignment_id = &amp;quot; + params[:id].to_s)&lt;br /&gt;
      if !@topics.nil?&lt;br /&gt;
        i=0&lt;br /&gt;
        @topics.each { |topic|&lt;br /&gt;
        ......&lt;br /&gt;
        i = i + 1&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==Case 3 : Modularize Code in application.rb==&lt;br /&gt;
===Current Scenario===&lt;br /&gt;
In the assignment.rb model, there exists one method(check_condition) which checks whether review, meta-review, etc are allowed or not. This method makes database calls to TopicDeadline table, DueDate and DeadlineType tables. Following is the code which was existing before the changes were made. It has the logic to find the nearest due date that hasn't passed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     drop_topic_deadline_id = DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
    if self.staggered_deadline?&lt;br /&gt;
      &lt;br /&gt;
      if topic_id&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                   topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
      else&lt;br /&gt;
        &lt;br /&gt;
        next_due_date = TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      next_due_date = DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                                  self.id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
===After changes===&lt;br /&gt;
The database queries have been moved to their respective models. The queries to TopicDeadline table, DueDate table and DeadlineType table have been moved to their models. Below is the new code in assignments.rb model which calls TopicDeadline.rb, DueDate.rb and DeadlineType.rb respectively for the queries in their tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;assignment.rb&amp;lt;/b&amp;gt; model&lt;br /&gt;
&lt;br /&gt;
 if self.staggered_deadline?&lt;br /&gt;
   next_due_date = TopicDeadline.find_next_due_date(topic_id,self.id)&lt;br /&gt;
 else&lt;br /&gt;
   next_due_date = DueDate.find_next_due_date(self.id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; defined in &amp;lt;b&amp;gt;topic_deadline.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
 def self.find_next_due_date(topic_id,assignment_id)&lt;br /&gt;
    drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
    if topic_id&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['topic_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         topic_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
    else&lt;br /&gt;
      TopicDeadline.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                         assignment_id, Time.now, drop_topic_deadline_id], :joins =&amp;gt; {:topic =&amp;gt; :assignment}, :order =&amp;gt; 'due_at')&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_next_due_date&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;due_date.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_next_due_date(assignment_id&lt;br /&gt;
   drop_topic_deadline_id = DeadlineType.find_drop_topic_deadline_id()&lt;br /&gt;
   DueDate.find(:first, :conditions =&amp;gt; ['assignment_id = ? and due_at &amp;gt;= ? and deadline_type_id &amp;lt;&amp;gt; ?', &lt;br /&gt;
                assignment_id, Time.now, drop_topic_deadline_id], :order =&amp;gt; 'due_at')&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
New &amp;lt;b&amp;gt;find_drop_topic_deadline_id&amp;lt;/b&amp;gt; method defined in &amp;lt;b&amp;gt;deadline_type.rb&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 def self.find_drop_topic_deadline_id()&lt;br /&gt;
   DeadlineType.find_by_name('drop_topic').id&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
== Case 4 : DeadCode Elimination in  sign_up_sheet_controller.rb ==&lt;br /&gt;
&lt;br /&gt;
The local variables topic_set and topic under the staggered deadline check statement were never used in the entire scope of the project , it introduced code smells. So it was checked if there was any reference to this code, and upon discovering it was not used anywhere, we decided to eliminate this [http://en.wikipedia.org/wiki/Dead_code_elimination deadcode].&lt;br /&gt;
 &lt;br /&gt;
===Current Scenario===&lt;br /&gt;
&lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      topic_set = Array.new&lt;br /&gt;
      topic = @sign_up_topic.id&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
===After Changes===&lt;br /&gt;
 &lt;br /&gt;
 def create_default_for_microtask&lt;br /&gt;
    .....&lt;br /&gt;
  &lt;br /&gt;
    .....&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Steps to verify changes=&lt;br /&gt;
Log into the application with the user having instructor's role or super user's role.&lt;br /&gt;
&lt;br /&gt;
1. Go to Manage -&amp;gt; Assignments and hover over the assignment “StaggeredDeadlines_Refactoring”.&lt;br /&gt;
&lt;br /&gt;
2. Click on “New Topic”.&lt;br /&gt;
&lt;br /&gt;
3. Enter the details of the topic you want to create. Create at least 2 topics for better analysis of the project.&lt;br /&gt;
&lt;br /&gt;
[[File:AddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
4. Now once you have created two new topics , then Click on  “Show start/due date”.&lt;br /&gt;
&lt;br /&gt;
5. You should be able to view the new start and due dates of your topics confirming these are the staggered deadlines for “StaggeredDeadlines_Refactoring” which has many topics with different deadlines.&lt;br /&gt;
&lt;br /&gt;
[[File:ShowdueDate.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now to view the difference between the Stagerred and Non-Staggered Deadlines, follow steps.&lt;br /&gt;
&lt;br /&gt;
7. Go to Manage -&amp;gt; Assignments and hover over “SALT Demo” and click on “Edit  Signup sheet”.&lt;br /&gt;
&lt;br /&gt;
8. Click on “New Topic” and fill in the details for a new topic.&lt;br /&gt;
&lt;br /&gt;
[[File:NonstaggeredAddTopic.png]]&lt;br /&gt;
&lt;br /&gt;
9. Now you will be able to see that there is no option for “Show Start/Due Date” which is because of the reason that this is not a staggered assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:NodueDate.png]]&lt;br /&gt;
&lt;br /&gt;
10. Hence there is only one due date and has no dependencies on others.&lt;br /&gt;
&lt;br /&gt;
= Concise Report on Refactoring =&lt;br /&gt;
&lt;br /&gt;
The project had redundant code, multiple functionalities in a method and extra conditional statements in controller, model and view files. We analyzed each occurrence of these issues, thus creating a list which needed to be refactored. Controllers like sign_up_sheet_controler, assignment.rb, due_date.rb,deadline_types.rb along with other files were modified. It's very difficult to explain the sequential and detailed procedure, but it has been explained in the sections above within the capacity of the Wiki.&lt;br /&gt;
&lt;br /&gt;
= Additional Learning and Future Work=&lt;br /&gt;
&lt;br /&gt;
In current implementation, our database has two tables for staggered and non-staggered deadlines. For any future improvements, we can make use of [http://blog.thirst.co/post/14885390861/rails-single-table-inheritance STI (Single Table Inheritance)] and analyze if applying STI would really impact query performance when application runs and extracts data from database.&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://eewang.github.io/blog/2013/03/12/how-and-when-to-use-single-table-inheritance-in-rails/ Single Table Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_refactoring Code Refactoring]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_smell Code smell]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=90664</id>
		<title>CSC/ECE 517 Fall 2014</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=90664"/>
		<updated>2014-10-29T19:15:10Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2014/sample_page]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 22 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 19 mx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 3 zq]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 lf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 wl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a a7 ch]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 rs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 jf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 os]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 15 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 10 hu]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 kv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 21 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 24 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 6 rl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 2 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 16 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 rm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 sj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 23 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 rn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 22 sp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss M1454 rss]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 gn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 13 va]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 kn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 ks]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 7 kz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_6_bn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 10 zz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 16 va]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a F1415 rv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_3_cp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1b 26 sa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_28_cg]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 29 ry]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 30 cs]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_33_jy]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_27_js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1453 syy]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1463 vpd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1465 oak]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1456_kdv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1453_sst]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_E1456_akk]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1455_asa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1458_sst]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1457_ags]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1466_gjf]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1452_jns]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1462_nms]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_S1455_ajp]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_S1454_ccc]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1450_cxm]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1455_skn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_M1450_vda]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1467_rsv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1464_vnn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/OSS_M1451_ahs]]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88728</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88728"/>
		<updated>2014-09-26T03:44:39Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Option 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1 : Customizing response in Controller Layer===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2: Customizing response in Model Layer===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database and the programmer may decide not to implement an Employee model as an Active Record. However the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer===&lt;br /&gt;
Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
===Custom response attributes===&lt;br /&gt;
It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Separation of Concerns===&lt;br /&gt;
The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Maintainability===&lt;br /&gt;
Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
&lt;br /&gt;
===Step 1 : Controller===&lt;br /&gt;
The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
&lt;br /&gt;
===Step 2 : Action Method===&lt;br /&gt;
The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
&lt;br /&gt;
===Step 3 : Active Model Serializer===&lt;br /&gt;
The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
Instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Time to write some code now.&lt;br /&gt;
&lt;br /&gt;
===Step1 : Install gem ===&lt;br /&gt;
Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Step2 : Update bundle===&lt;br /&gt;
Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step3 : Generate Serializer Class===&lt;br /&gt;
This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step4 : Customize Serializer===&lt;br /&gt;
Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee, although the Employee Active Model does not have any such attribute. We also add a custom attribute '''EmpConciseDetails''' that appends two attributes of an Employee. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url or EmpConciseDetails.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes  :url, :EmpConciseDetails&lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
  &lt;br /&gt;
  def EmpConciseDetails&lt;br /&gt;
    :name + &amp;quot; &amp;quot; + :age&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step5 : Get Custom object formatting===&lt;br /&gt;
That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url token to view the Employee and Employee name and age in concise form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   url: /employees/1.json&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88726</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88726"/>
		<updated>2014-09-26T03:44:26Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Option 1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1 : Customizing response in Controller Layer===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database and the programmer may decide not to implement an Employee model as an Active Record. However the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer===&lt;br /&gt;
Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
===Custom response attributes===&lt;br /&gt;
It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Separation of Concerns===&lt;br /&gt;
The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Maintainability===&lt;br /&gt;
Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
&lt;br /&gt;
===Step 1 : Controller===&lt;br /&gt;
The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
&lt;br /&gt;
===Step 2 : Action Method===&lt;br /&gt;
The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
&lt;br /&gt;
===Step 3 : Active Model Serializer===&lt;br /&gt;
The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
Instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Time to write some code now.&lt;br /&gt;
&lt;br /&gt;
===Step1 : Install gem ===&lt;br /&gt;
Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Step2 : Update bundle===&lt;br /&gt;
Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step3 : Generate Serializer Class===&lt;br /&gt;
This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step4 : Customize Serializer===&lt;br /&gt;
Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee, although the Employee Active Model does not have any such attribute. We also add a custom attribute '''EmpConciseDetails''' that appends two attributes of an Employee. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url or EmpConciseDetails.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes  :url, :EmpConciseDetails&lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
  &lt;br /&gt;
  def EmpConciseDetails&lt;br /&gt;
    :name + &amp;quot; &amp;quot; + :age&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step5 : Get Custom object formatting===&lt;br /&gt;
That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url token to view the Employee and Employee name and age in concise form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   url: /employees/1.json&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88722</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88722"/>
		<updated>2014-09-26T03:43:22Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Using Active Model Serializer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database and the programmer may decide not to implement an Employee model as an Active Record. However the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer===&lt;br /&gt;
Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
===Custom response attributes===&lt;br /&gt;
It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Separation of Concerns===&lt;br /&gt;
The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Maintainability===&lt;br /&gt;
Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
&lt;br /&gt;
===Step 1 : Controller===&lt;br /&gt;
The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
&lt;br /&gt;
===Step 2 : Action Method===&lt;br /&gt;
The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
&lt;br /&gt;
===Step 3 : Active Model Serializer===&lt;br /&gt;
The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
Instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Time to write some code now.&lt;br /&gt;
&lt;br /&gt;
===Step1 : Install gem ===&lt;br /&gt;
Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Step2 : Update bundle===&lt;br /&gt;
Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step3 : Generate Serializer Class===&lt;br /&gt;
This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step4 : Customize Serializer===&lt;br /&gt;
Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee, although the Employee Active Model does not have any such attribute. We also add a custom attribute '''EmpConciseDetails''' that appends two attributes of an Employee. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url or EmpConciseDetails.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes  :url, :EmpConciseDetails&lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
  &lt;br /&gt;
  def EmpConciseDetails&lt;br /&gt;
    :name + &amp;quot; &amp;quot; + :age&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step5 : Get Custom object formatting===&lt;br /&gt;
That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url token to view the Employee and Employee name and age in concise form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   url: /employees/1.json&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88717</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88717"/>
		<updated>2014-09-26T03:40:45Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* How Active Model Serializer Works? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database and the programmer may decide not to implement an Employee model as an Active Record. However the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer===&lt;br /&gt;
Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
===Custom response attributes===&lt;br /&gt;
It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Separation of Concerns===&lt;br /&gt;
The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Maintainability===&lt;br /&gt;
Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
&lt;br /&gt;
===Step 1 : Controller===&lt;br /&gt;
The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
&lt;br /&gt;
===Step 2 : Action Method===&lt;br /&gt;
The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
&lt;br /&gt;
===Step 3 : Active Model Serializer===&lt;br /&gt;
The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
Instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Time to write some code now.&lt;br /&gt;
&lt;br /&gt;
===Step1===&lt;br /&gt;
Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Step2===&lt;br /&gt;
Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step3===&lt;br /&gt;
This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step4===&lt;br /&gt;
Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee, although the Employee Active Model does not have any such attribute. We also add a custom attribute '''EmpConciseDetails''' that appends two attributes of an Employee. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url or EmpConciseDetails.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes  :url, :EmpConciseDetails&lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
  &lt;br /&gt;
  def EmpConciseDetails&lt;br /&gt;
    :name + &amp;quot; &amp;quot; + :age&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step5===&lt;br /&gt;
That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url token to view the Employee and Employee name and age in concise form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   url: /employees/1.json&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88715</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88715"/>
		<updated>2014-09-26T03:39:51Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Why Active Model Serializers? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database and the programmer may decide not to implement an Employee model as an Active Record. However the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer===&lt;br /&gt;
Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
===Custom response attributes===&lt;br /&gt;
It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Separation of Concerns===&lt;br /&gt;
The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Maintainability===&lt;br /&gt;
Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
&lt;br /&gt;
===Step 1===&lt;br /&gt;
The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
&lt;br /&gt;
===Step 2===&lt;br /&gt;
The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
&lt;br /&gt;
===Step 3===&lt;br /&gt;
The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
Instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Time to write some code now.&lt;br /&gt;
&lt;br /&gt;
===Step1===&lt;br /&gt;
Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Step2===&lt;br /&gt;
Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step3===&lt;br /&gt;
This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step4===&lt;br /&gt;
Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee, although the Employee Active Model does not have any such attribute. We also add a custom attribute '''EmpConciseDetails''' that appends two attributes of an Employee. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url or EmpConciseDetails.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes  :url, :EmpConciseDetails&lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
  &lt;br /&gt;
  def EmpConciseDetails&lt;br /&gt;
    :name + &amp;quot; &amp;quot; + :age&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step5===&lt;br /&gt;
That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url token to view the Employee and Employee name and age in concise form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   url: /employees/1.json&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88658</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88658"/>
		<updated>2014-09-26T02:45:39Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Using Active Model Serializer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database and the programmer may decide not to implement an Employee model as an Active Record. However the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer===&lt;br /&gt;
Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
&lt;br /&gt;
===Step 1===&lt;br /&gt;
The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
&lt;br /&gt;
===Step 2===&lt;br /&gt;
The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
&lt;br /&gt;
===Step 3===&lt;br /&gt;
The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
Instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Time to write some code now.&lt;br /&gt;
&lt;br /&gt;
===Step1===&lt;br /&gt;
Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Step2===&lt;br /&gt;
Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step3===&lt;br /&gt;
This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step4===&lt;br /&gt;
Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee, although the Employee Active Model does not have any such attribute. We also add a custom attribute '''EmpConciseDetails''' that appends two attributes of an Employee. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url or EmpConciseDetails.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes  :url, :EmpConciseDetails&lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
  &lt;br /&gt;
  def EmpConciseDetails&lt;br /&gt;
    :name + &amp;quot; &amp;quot; + :age&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step5===&lt;br /&gt;
That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url token to view the Employee and Employee name and age in concise form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   url: /employees/1.json&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88657</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88657"/>
		<updated>2014-09-26T02:44:12Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* How Active Model Serializer Works? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database and the programmer may decide not to implement an Employee model as an Active Record. However the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer===&lt;br /&gt;
Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
&lt;br /&gt;
===Step 1===&lt;br /&gt;
The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
&lt;br /&gt;
===Step 2===&lt;br /&gt;
The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
&lt;br /&gt;
===Step 3===&lt;br /&gt;
The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
Instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Time to write some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee, although the Employee Active Model does not have any such attribute. We also add a custom attribute '''EmpConciseDetails''' that appends two attributes of an Employee. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url or EmpConciseDetails.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes  :url, :EmpConciseDetails&lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
  &lt;br /&gt;
  def EmpConciseDetails&lt;br /&gt;
    :name + &amp;quot; &amp;quot; + :age&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url token to view the Employee and Employee name and age in concise form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   url: /employees/1.json&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88656</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88656"/>
		<updated>2014-09-26T02:43:32Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* How Active Model Serializer Works? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database and the programmer may decide not to implement an Employee model as an Active Record. However the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer===&lt;br /&gt;
Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
&lt;br /&gt;
===Step 1===&lt;br /&gt;
The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
&lt;br /&gt;
===Step 2===&lt;br /&gt;
The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
&lt;br /&gt;
===Step 3===&lt;br /&gt;
The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Time to write some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee, although the Employee Active Model does not have any such attribute. We also add a custom attribute '''EmpConciseDetails''' that appends two attributes of an Employee. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url or EmpConciseDetails.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes  :url, :EmpConciseDetails&lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
  &lt;br /&gt;
  def EmpConciseDetails&lt;br /&gt;
    :name + &amp;quot; &amp;quot; + :age&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url token to view the Employee and Employee name and age in concise form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   url: /employees/1.json&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88655</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88655"/>
		<updated>2014-09-26T02:42:39Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database and the programmer may decide not to implement an Employee model as an Active Record. However the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer===&lt;br /&gt;
Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Time to write some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee, although the Employee Active Model does not have any such attribute. We also add a custom attribute '''EmpConciseDetails''' that appends two attributes of an Employee. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url or EmpConciseDetails.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes  :url, :EmpConciseDetails&lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
  &lt;br /&gt;
  def EmpConciseDetails&lt;br /&gt;
    :name + &amp;quot; &amp;quot; + :age&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url token to view the Employee and Employee name and age in concise form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   url: /employees/1.json&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88651</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88651"/>
		<updated>2014-09-26T02:37:19Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Using Active Model Serializer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database and the programmer may decide not to implement an Employee model as an Active Record. However the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer===&lt;br /&gt;
Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Time to write some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee, although the Employee Active Model does not have any such attribute. We also add a custom attribute '''EmpConciseDetails''' that appends two attributes of an Employee. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id, :name, :age, :url &lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
  &lt;br /&gt;
  def EmpConciseDetails&lt;br /&gt;
    :name + &amp;quot; &amp;quot; + :age&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url key value pair to view the Employee.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88648</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88648"/>
		<updated>2014-09-26T02:33:38Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Using Active Model Serializer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database and the programmer may decide not to implement an Employee model as an Active Record. However the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer===&lt;br /&gt;
Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Time to write some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee although the Employee Active Model does not have any such attribute. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id, :name, :age, :url &lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url key value pair to view the Employee.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88645</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88645"/>
		<updated>2014-09-26T02:30:12Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Active Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database and the programmer may decide not to implement an Employee model as an Active Record. However the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer===&lt;br /&gt;
Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Let us see some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee although the Employee Active Model does not have any such attribute. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id, :name, :age, :url &lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url key value pair to view the Employee.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88644</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88644"/>
		<updated>2014-09-26T02:28:29Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Active Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database. But the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer===&lt;br /&gt;
Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Let us see some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee although the Employee Active Model does not have any such attribute. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id, :name, :age, :url &lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url key value pair to view the Employee.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88643</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88643"/>
		<updated>2014-09-26T02:28:11Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database. But the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer====Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Let us see some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee although the Employee Active Model does not have any such attribute. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id, :name, :age, :url &lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url key value pair to view the Employee.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88642</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88642"/>
		<updated>2014-09-26T02:28:01Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
&lt;br /&gt;
===Active Model===&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database. But the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
===Serializer====&lt;br /&gt;
Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
===API Server Application===&lt;br /&gt;
API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Let us see some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee although the Employee Active Model does not have any such attribute. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id, :name, :age, :url &lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url key value pair to view the Employee.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88640</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88640"/>
		<updated>2014-09-26T02:27:14Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
;Active Model&lt;br /&gt;
'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database. But the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
;Serializer&lt;br /&gt;
:Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
;API Server Application&lt;br /&gt;
:API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Let us see some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee although the Employee Active Model does not have any such attribute. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id, :name, :age, :url &lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url key value pair to view the Employee.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88639</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88639"/>
		<updated>2014-09-26T02:26:52Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Knowledge of the following terms would help before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
;Active Model&lt;br /&gt;
:'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? &lt;br /&gt;
&lt;br /&gt;
It may not always be the case that the Employee model has to be backed by a database. But the programmer might want some of the model attribute validation functionality that an Active Record provides. For eg: Imagine an employee records system that handles an create employee form by reading the POST data into an Employee object. The system does not persist this Employee model to any database though. It simply emails the admin with all the captured data present in the Employee model. However before emailing the programmer might want to validate if certain required attributes about the Employee are present.  &lt;br /&gt;
&lt;br /&gt;
The solution to this problem is the Active Model class. An '''Active Model''' is an Active Record devoid of all the database persistence functionality. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
;Serializer&lt;br /&gt;
:Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
;API Server Application&lt;br /&gt;
:API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Let us see some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee although the Employee Active Model does not have any such attribute. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id, :name, :age, :url &lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url key value pair to view the Employee.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88633</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88633"/>
		<updated>2014-09-26T02:18:05Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Let us familiarize ourselves with a few terms before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
;Active Model&lt;br /&gt;
:'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? It may not always be the case that we want our Employee model to be backed by a database. But we might want to have all the functionality that an Active Record provides (for example, validations on the Employee model to check if name is present on the Employee Active Record before persisting it or checking if the active record got dirtied because of an attribute change etc. ). An example of this is, as and when an Employee create form is submitted, we might want to just send an email to the admin with the new employee data once we validate that data. An '''Active Model''' does just this. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
;Serializer&lt;br /&gt;
:Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
;API Server Application&lt;br /&gt;
:API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Let us see some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee although the Employee Active Model does not have any such attribute. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id, :name, :age, :url &lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url key value pair to view the Employee.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88632</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88632"/>
		<updated>2014-09-26T02:17:45Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Let us familiarize ourselves with a few terms before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
;Active Model&lt;br /&gt;
:'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? It may not always be the case that we want our Employee model to be backed by a database. But we might want to have all the functionality that an Active Record provides (for example, validations on the Employee model to check if name is present on the Employee Active Record before persisting it or checking if the active record got dirtied because of an attribute change etc. ). An example of this is, as and when an Employee create form is submitted, we might want to just send an email to the admin with the new employee data once we validate that data. An '''Active Model''' does just this. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
;Serializer&lt;br /&gt;
:Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
;API Server Application&lt;br /&gt;
:API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Let us see some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee although the Employee Active Model does not have any such attribute. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id, :name, :age, :url &lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url key value pair to view the Employee.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88631</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88631"/>
		<updated>2014-09-26T02:17:07Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Option 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the '''as_json''' method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Let us familiarize ourselves with a few terms before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
;Active Model&lt;br /&gt;
:'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? It may not always be the case that we want our Employee model to be backed by a database. But we might want to have all the functionality that an Active Record provides (for example, validations on the Employee model to check if name is present on the Employee Active Record before persisting it or checking if the active record got dirtied because of an attribute change etc. ). An example of this is, as and when an Employee create form is submitted, we might want to just send an email to the admin with the new employee data once we validate that data. An '''Active Model''' does just this. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
;Serializer&lt;br /&gt;
:Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
;API Server Application&lt;br /&gt;
:API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Let us see some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee although the Employee Active Model does not have any such attribute. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id, :name, :age, :url &lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url key value pair to view the Employee.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88629</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88629"/>
		<updated>2014-09-26T02:15:42Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. &lt;br /&gt;
&lt;br /&gt;
===Option 1===&lt;br /&gt;
&lt;br /&gt;
The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request. The below method fetches the desired Employee and returns its JSON representation to the client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying '''root: false''' above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
===Option 2===&lt;br /&gt;
&lt;br /&gt;
Another option is to override the as_json method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above '''as_json''' method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom '''as_json''' method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through '''Active model serializers''' we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The advantages of this scheme are dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach. Specifics are discussed in following sections.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Let us familiarize ourselves with a few terms before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
;Active Model&lt;br /&gt;
:'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? It may not always be the case that we want our Employee model to be backed by a database. But we might want to have all the functionality that an Active Record provides (for example, validations on the Employee model to check if name is present on the Employee Active Record before persisting it or checking if the active record got dirtied because of an attribute change etc. ). An example of this is, as and when an Employee create form is submitted, we might want to just send an email to the admin with the new employee data once we validate that data. An '''Active Model''' does just this. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
;Serializer&lt;br /&gt;
:Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
;API Server Application&lt;br /&gt;
:API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Let us see some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee although the Employee Active Model does not have any such attribute. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id, :name, :age, :url &lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url key value pair to view the Employee.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88626</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88626"/>
		<updated>2014-09-26T02:11:08Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: /* Active Model Serializers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which helps the API designers to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying root: false above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
Another option is to override the as_json method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above as_json method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom as_json method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through Active model serializers we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The effect of this scheme is dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach which is described in later sections.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Let us familiarize ourselves with a few terms before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
;Active Model&lt;br /&gt;
:'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? It may not always be the case that we want our Employee model to be backed by a database. But we might want to have all the functionality that an Active Record provides (for example, validations on the Employee model to check if name is present on the Employee Active Record before persisting it or checking if the active record got dirtied because of an attribute change etc. ). An example of this is, as and when an Employee create form is submitted, we might want to just send an email to the admin with the new employee data once we validate that data. An '''Active Model''' does just this. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
;Serializer&lt;br /&gt;
:Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
;API Server Application&lt;br /&gt;
:API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Let us see some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee although the Employee Active Model does not have any such attribute. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id, :name, :age, :url &lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url key value pair to view the Employee.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88625</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 24 sa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_24_sa&amp;diff=88625"/>
		<updated>2014-09-26T02:10:15Z</updated>

		<summary type="html">&lt;p&gt;Shjoshi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Active Model Serializers=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] offers strong features to write API based server applications, which expose data through a well designed API and serve data in various formats as requested. One of these features is '''[http://github.com/rails-api/active_model_serializers Active Model Serializers]''' which help the API designer to have fine control over the response generated by the API to a data request. '''Active Model Serializers''' help programmers do this very easily and cleanly without breaking separation of concerns in a rails application. They promote [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration], thus reducing code bloat and increasing code scalibility and readability.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ClientServer.png‎|right|]]&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
 &lt;br /&gt;
The modern web has seen more and more web applications that are written as web services or web APIs. These applications do not return a web page to the client browser, but return just the bare bones data to the client in the format requested. This gives the clients the liberty to develop customized User Interfaces for the same web application. A common example is the Rotten Tomatoes API which offers movie data in JSON, XML and various other formats. The clients request the Rotten Tomatoes web server for the data in the desired format, and the web server is able to respond with the correct data in the required format. &lt;br /&gt;
&lt;br /&gt;
Active Model Serializers are a way for Web API designers who use Ruby on Rails to have full control over the formatting and the content of data that is returned to clients. For eg. An employee data model returned as JSON to a data request might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{Employee: {&lt;br /&gt;
              name: emp_name&lt;br /&gt;
              age: 26&lt;br /&gt;
              salary: 35000&lt;br /&gt;
              weight: 90kg&lt;br /&gt;
              height: 170&lt;br /&gt;
           }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the API designer may want to improve this formatting and exclude certain fields so that the response is just the data without clubbing it under the &amp;quot;Employee&amp;quot; root token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   EmpConciseDetails: emp_name 26&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In a Ruby On Rails application there could be a couple of ways to achieve this. The first one is shown below where we can specify the JSON formatting option in the action method which handles the data request:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @emp = Employee.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|      &lt;br /&gt;
      format.json { render :json =&amp;gt; @emp, root:false}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifying root: false above will remove the unwanted Employee token from the resultant JSON. However this method is not recommended as we are littering our controller layer with data formatting code. If we want to maintain the MVC separation of concerns, formatting the response data does not belong in the controller layer.&lt;br /&gt;
&lt;br /&gt;
Another option is to override the as_json method of the Employee data model which is typically an Active Record in a Rails application:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Employee &amp;lt; ActiveRecord&lt;br /&gt;
&lt;br /&gt;
def as_json(options)  &lt;br /&gt;
  super(:only =&amp;gt; [:name, :age])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above as_json method is called whenever Rails has to convert the Employee object to its JSON format to send to the client. Our custom as_json method will help us return only the name and the age as desired. However we again have a problem as we are littering our Model layer with custom formatting tasks which it is not intended to handle. &lt;br /&gt;
&lt;br /&gt;
Through Active model serializers we are able to place these custom formatting tasks to a separate class namely an EmployeeSerializer which inherits from ActiveModel::Serializer class. The Rails application is able to discover this serializer when Employee data model has to be serialized without any configuration from the programmer's side. The effect of this scheme is dual. It helps keep separation of concerns in the Rails application, and its done with a convention over configuration approach which is described in later sections.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
Let us familiarize ourselves with a few terms before getting to the usage of '''Active Model Serializers'''.&lt;br /&gt;
;Active Model&lt;br /&gt;
:'''[http://railscasts.com/episodes/219-active-model Active Model]''' is closely related to the widely used concept of '''[http://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord Active Record]''' in the Rails world. '''Active Record''' is an object that maps directly to the data in our database. An '''Active Record''' takes care of fetching and saving data to the database. For example, in an employee records application an Employee Active Record helps to persist a newly created/edited Employee. So how is an '''Active Model''' different? It may not always be the case that we want our Employee model to be backed by a database. But we might want to have all the functionality that an Active Record provides (for example, validations on the Employee model to check if name is present on the Employee Active Record before persisting it or checking if the active record got dirtied because of an attribute change etc. ). An example of this is, as and when an Employee create form is submitted, we might want to just send an email to the admin with the new employee data once we validate that data. An '''Active Model''' does just this. Infact, the rails developers segregated all the non database functionality out of an '''Active Record''' into an '''Active Model'''.&lt;br /&gt;
&lt;br /&gt;
;Serializer&lt;br /&gt;
:Serializer is a small program that takes an object residing in program memory (for example: could be a C# object in an ASP.NET application, or an ActiveModel object in a Rails application) and converts this information into format that is transferrable over the wire, for example, JSON and XML. This is required because the client may be written in Java and there is no way for it to read an Active Model Ruby Object that exists in memory on the server side.&lt;br /&gt;
&lt;br /&gt;
;API Server Application&lt;br /&gt;
:API Server application is an application which serves data requests coming from a variety of clients (for example: mobile, desktop) in various formats such as JSON, XML. For example, An employee data web service which returns employee age and name in both JSON and XML&lt;br /&gt;
&lt;br /&gt;
=Why Active Model Serializers?=&lt;br /&gt;
&lt;br /&gt;
* '''Custom response attributes:''' It is not always the case that an API application serves a request by responding with data as it is stored on the server. The API designer has a task of exposing just the right data to the clients and hence needs fine control over exactly what part of the data on the server is returned in a response. An Active Model Serializer could help return just the Employee age and name to the client as JSON and ignore all the other attributes set on an Employee Model.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Separation of Concerns:''' The response data could also be customized in the respond_to method of the rails controller action or for example, by implementing a custom as_json method on the model class. However this breaks the separation of concerns principle as we let something like formatting the response data venture into the controller and model layer. With Active Model Serializers we can keep this functionality segregated from the application.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Maintainability:''' Client needs keep changing. Let's say a Client requests some changes to the API response data, only the Active Model Serializer would get affected and there are no side effects on the Controller or the Model itself.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=How Active Model Serializer Works?=&lt;br /&gt;
[[File:Active-Model-Serializer2.png‎|right]]&lt;br /&gt;
&lt;br /&gt;
Active Model Serializers work with the help of two components namely '''Serializer''' and '''Adapter'''. Let's say we wanted to write an Active Model Serializer for customizing an API that returns Employee data as json. We would have to write an '''EmployeeSerializer''' which is configured to use a '''JsonApiAdapter'''. The '''Serializer''' Component would specify which attributes and relationships of Employee to other models would be captured in the response data. For example, it might choose to return the Employee name, age and the data about the employee's family members which are different models. The '''Adapter''' component specifies how to format this selected Employee data in the correct format as required by the client. A JsonApiAdapter would format it as JSON and is the default adapter used by an Active Model Serializer. However you can always supply your own Adapter for the serializer to use.&lt;br /&gt;
&lt;br /&gt;
Assume the Employee data API scenario cited above and Refer to the figure. &lt;br /&gt;
#The Controller receives the request for json data and routes it to a specific action method&lt;br /&gt;
#The action method has a respond_to method that returns Employee model as JSON. When Rails encounters this line, it looks for an EmployeeSerializer in the project specifically in a file employee_serializer to get the exact data to be put into the response.&lt;br /&gt;
#The EmployeeSerializer is by default configured to use a JsonApiAdapter and formats the specified attributes and relationships in the JSON format. This forms the final customized response.&lt;br /&gt;
&lt;br /&gt;
As you can see, instead of returning the default JSON conversion of the Employee model from the respond_to method, that Rails does automatically for us, we were able to customize our API response data through the use of Active Model Serializers in a non-intrusive way maintaining separation from the controller and the model layers.&lt;br /&gt;
&lt;br /&gt;
=Using Active Model Serializer=&lt;br /&gt;
&lt;br /&gt;
Let us see some code now.&lt;br /&gt;
&lt;br /&gt;
'''Step 1:''' Active Model Serializer is available as a gem. Add to the gem file the following line :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem 'active_model_serializers'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 2:''' Run the following command at the terminal window to install the gem.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bundle update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 3:''' This gem provides a serializer generator for the selected Active Model. For example, if employee was your Active Model run :&lt;br /&gt;
rails g serializer employee&lt;br /&gt;
&lt;br /&gt;
This would create a file employee_serializer.rb containing the following code in the newly created app/serializers directory of your project:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 4:''' Add your custom attributes and any other customizations to this file. For example: We are adding a url attribute to get details of this employee although the Employee Active Model does not have any such attribute. We add it because the client might be interested in it. That is the power of Active Model Serializer. It does not require us to define another property on the Employee Active Model to return its Url.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class EmployeeSerializer &amp;lt; ActiveModel::Serializer&lt;br /&gt;
  attributes :id, :name, :age, :url &lt;br /&gt;
 &lt;br /&gt;
  def url&lt;br /&gt;
    employee_url(object)&lt;br /&gt;
  end  &lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Step 5:''' That's it! Whenever an Employee is requested the custom EmployeeSerializer does the task of serializing the employee to json and will now include a url key value pair to view the Employee.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://railscasts.com/episodes/409-active-model-serializers Railcast on Active Model Serializers]&lt;br /&gt;
#[https://github.com/rails-api/active_model_serializers Active Model Serializer module on github]&lt;br /&gt;
#[http://asciicasts.com/episodes/409-active-model-serializers Active Model Serializer Asciicast]&lt;br /&gt;
#[https://www.youtube.com/watch?v=G6ipU6AiEXY Active Model Serializer Video Tutorial]&lt;br /&gt;
#[http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ Active Model]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Serialization Serialization wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/JSON JSON wiki]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/RubyGems RubyGems wiki]&lt;/div&gt;</summary>
		<author><name>Shjoshi2</name></author>
	</entry>
</feed>