<?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=Nmanjun3</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=Nmanjun3"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Nmanjun3"/>
	<updated>2026-06-02T03:19:03Z</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_2012/ch2a_2w30_an&amp;diff=68811</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68811"/>
		<updated>2012-10-27T01:45:21Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* Also see */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Testing plays a major role in the software development cycle. It is a well known fact that mandatory testing of every functionality implemented be done so as to ensure that the code does not break when in production. Testing can be done in four main stages: Unit testing (individual code modules are tested for flaws and re-coded if any errors are found), Integration testing (various interacting modules are put together piece by piece to ensure that seamless integration exists among them), System testing (the system is tested as a whole after it has been fully integrated) and Acceptance testing (potential users test the system for flaws in design or execution and to see if the product matches their expectation). &lt;br /&gt;
&lt;br /&gt;
This article focuses on Unit testing by following the Test Driven Development approach for Ruby using RSpec framework as explained in this [https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu SaaS] video.&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] &amp;lt;sup&amp;gt;[http://rspec.info/]&amp;lt;/sup&amp;gt;. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/ JBehave] which is another BDD testing framework &amp;lt;sup&amp;gt;[http://en.wikipedia.org/wiki/RSpec]&amp;lt;/sup&amp;gt;. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host &amp;lt;sup&amp;gt;[http://en.wikipedia.org/wiki/Domain-specific_language]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a            [http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step &amp;lt;sup&amp;gt;[http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/]&amp;lt;/sup&amp;gt;. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#http://rspec.info/&lt;br /&gt;
#http://en.wikipedia.org/wiki/RSpec&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language&lt;br /&gt;
#http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/&lt;br /&gt;
&lt;br /&gt;
=Also see=&lt;br /&gt;
*https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu&lt;br /&gt;
*http://en.wikipedia.org/wiki/Software_quality_assurance &lt;br /&gt;
*http://en.wikipedia.org/wiki/Test-driven_development &lt;br /&gt;
*http://en.wikipedia.org/wiki/Regular_expression&lt;br /&gt;
*http://en.wikipedia.org/wiki/SQL&lt;br /&gt;
*http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
*http://en.wikipedia.org/wiki/Behavior-driven_development&lt;br /&gt;
*http://jbehave.org/&lt;br /&gt;
*http://en.wikipedia.org/wiki/Domain-specific_language&lt;br /&gt;
*http://guides.rubyonrails.org/command_line.html&lt;br /&gt;
*http://en.wikipedia.org/wiki/Cucumber_%28software%29&lt;br /&gt;
*http://pastebin.com/kJxjwSF6&lt;br /&gt;
&lt;br /&gt;
=Other Interesting Links=&lt;br /&gt;
*[http://net.tutsplus.com/tutorials/php/the-newbies-guide-to-test-driven-development/ Newbies guide to TDD]&lt;br /&gt;
*[http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial The 30 minute Regex tutorial]&lt;br /&gt;
*[http://www.andrejkoelewijn.com/wp/2008/10/27/sql-is-a-dsl/ SQL is a DSL]&lt;br /&gt;
*[https://www.relishapp.com/rspec RSpec]&lt;br /&gt;
*[https://www.relishapp.com/rspec/rspec-rails/v/2-0/docs/helper-specs/helper-spec Spec helper]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68807</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68807"/>
		<updated>2012-10-27T01:44:30Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Testing plays a major role in the software development cycle. It is a well known fact that mandatory testing of every functionality implemented be done so as to ensure that the code does not break when in production. Testing can be done in four main stages: Unit testing (individual code modules are tested for flaws and re-coded if any errors are found), Integration testing (various interacting modules are put together piece by piece to ensure that seamless integration exists among them), System testing (the system is tested as a whole after it has been fully integrated) and Acceptance testing (potential users test the system for flaws in design or execution and to see if the product matches their expectation). &lt;br /&gt;
&lt;br /&gt;
This article focuses on Unit testing by following the Test Driven Development approach for Ruby using RSpec framework as explained in this [https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu SaaS] video.&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] &amp;lt;sup&amp;gt;[http://rspec.info/]&amp;lt;/sup&amp;gt;. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/ JBehave] which is another BDD testing framework &amp;lt;sup&amp;gt;[http://en.wikipedia.org/wiki/RSpec]&amp;lt;/sup&amp;gt;. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host &amp;lt;sup&amp;gt;[http://en.wikipedia.org/wiki/Domain-specific_language]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a            [http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step &amp;lt;sup&amp;gt;[http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/]&amp;lt;/sup&amp;gt;. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#http://rspec.info/&lt;br /&gt;
#http://en.wikipedia.org/wiki/RSpec&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language&lt;br /&gt;
#http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/&lt;br /&gt;
&lt;br /&gt;
=Also see=&lt;br /&gt;
#https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu&lt;br /&gt;
#http://en.wikipedia.org/wiki/Software_quality_assurance &lt;br /&gt;
#http://en.wikipedia.org/wiki/Test-driven_development &lt;br /&gt;
#http://en.wikipedia.org/wiki/Regular_expression&lt;br /&gt;
#http://en.wikipedia.org/wiki/SQL&lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
#http://en.wikipedia.org/wiki/Behavior-driven_development&lt;br /&gt;
#http://jbehave.org/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language&lt;br /&gt;
#http://guides.rubyonrails.org/command_line.html&lt;br /&gt;
#http://en.wikipedia.org/wiki/Cucumber_%28software%29&lt;br /&gt;
#http://pastebin.com/kJxjwSF6&lt;br /&gt;
&lt;br /&gt;
=Other Interesting Links=&lt;br /&gt;
*[http://net.tutsplus.com/tutorials/php/the-newbies-guide-to-test-driven-development/ Newbies guide to TDD]&lt;br /&gt;
*[http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial The 30 minute Regex tutorial]&lt;br /&gt;
*[http://www.andrejkoelewijn.com/wp/2008/10/27/sql-is-a-dsl/ SQL is a DSL]&lt;br /&gt;
*[https://www.relishapp.com/rspec RSpec]&lt;br /&gt;
*[https://www.relishapp.com/rspec/rspec-rails/v/2-0/docs/helper-specs/helper-spec Spec helper]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68801</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68801"/>
		<updated>2012-10-27T01:41:14Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Testing plays a major role in the software development cycle. It is a well known fact that mandatory testing of every functionality implemented be done so as to ensure that the code does not break when in production. Testing can be done in four main stages: Unit testing (individual code modules are tested for flaws and re-coded if any errors are found), Integration testing (various interacting modules are put together piece by piece to ensure that seamless integration exists among them), System testing (the system is tested as a whole after it has been fully integrated) and Acceptance testing (potential users test the system for flaws in design or execution and to see if the product matches their expectation). &lt;br /&gt;
&lt;br /&gt;
This article focuses on Unit testing by following the Test Driven Development approach for Ruby using RSpec framework as explained in this [https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu SaaS] video.&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] &amp;lt;sup&amp;gt;[http://rspec.info/]&amp;lt;/sup&amp;gt;. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/ JBehave] which is another BDD testing framework &amp;lt;sup&amp;gt;[http://en.wikipedia.org/wiki/RSpec]&amp;lt;/sup&amp;gt;. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host &amp;lt;sup&amp;gt;[http://en.wikipedia.org/wiki/Domain-specific_language]&amp;lt;/sup&amp;gt;.&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a            [http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step &amp;lt;sup&amp;gt;[http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/]&amp;lt;/sup&amp;gt;. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu&lt;br /&gt;
#http://en.wikipedia.org/wiki/Software_quality_assurance &lt;br /&gt;
#http://en.wikipedia.org/wiki/Test-driven_development&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language &lt;br /&gt;
#http://en.wikipedia.org/wiki/Regular_expression&lt;br /&gt;
#http://en.wikipedia.org/wiki/SQL&lt;br /&gt;
#http://en.wikipedia.org/wiki/RSpec&lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
#http://rspec.info/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Behavior-driven_development&lt;br /&gt;
#http://jbehave.org/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language&lt;br /&gt;
#http://guides.rubyonrails.org/command_line.html&lt;br /&gt;
#http://en.wikipedia.org/wiki/Cucumber_%28software%29&lt;br /&gt;
#http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/&lt;br /&gt;
#http://pastebin.com/kJxjwSF6&lt;br /&gt;
&lt;br /&gt;
=Other Interesting Links=&lt;br /&gt;
*[http://net.tutsplus.com/tutorials/php/the-newbies-guide-to-test-driven-development/ Newbies guide to TDD]&lt;br /&gt;
*[http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial The 30 minute Regex tutorial]&lt;br /&gt;
*[http://www.andrejkoelewijn.com/wp/2008/10/27/sql-is-a-dsl/ SQL is a DSL]&lt;br /&gt;
*[https://www.relishapp.com/rspec RSpec]&lt;br /&gt;
*[https://www.relishapp.com/rspec/rspec-rails/v/2-0/docs/helper-specs/helper-spec Spec helper]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68800</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68800"/>
		<updated>2012-10-27T01:40:30Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* The code we wish we had */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Testing plays a major role in the software development cycle. It is a well known fact that mandatory testing of every functionality implemented be done so as to ensure that the code does not break when in production. Testing can be done in four main stages: Unit testing (individual code modules are tested for flaws and re-coded if any errors are found), Integration testing (various interacting modules are put together piece by piece to ensure that seamless integration exists among them), System testing (the system is tested as a whole after it has been fully integrated) and Acceptance testing (potential users test the system for flaws in design or execution and to see if the product matches their expectation). &lt;br /&gt;
&lt;br /&gt;
This article focuses on Unit testing by following the Test Driven Development approach for Ruby using RSpec framework as explained in this [https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu SaaS] video.&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] &amp;lt;sup&amp;gt;[http://rspec.info/]&amp;lt;/sup&amp;gt;. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by &amp;lt;sup&amp;gt;[http://jbehave.org/ JBehave]&amp;lt;/sup&amp;gt; which is another BDD testing framework [http://en.wikipedia.org/wiki/RSpec]. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host [http://en.wikipedia.org/wiki/Domain-specific_language].&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a            [http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step &amp;lt;sup&amp;gt;[http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/]&amp;lt;/sup&amp;gt;. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu&lt;br /&gt;
#http://en.wikipedia.org/wiki/Software_quality_assurance &lt;br /&gt;
#http://en.wikipedia.org/wiki/Test-driven_development&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language &lt;br /&gt;
#http://en.wikipedia.org/wiki/Regular_expression&lt;br /&gt;
#http://en.wikipedia.org/wiki/SQL&lt;br /&gt;
#http://en.wikipedia.org/wiki/RSpec&lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
#http://rspec.info/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Behavior-driven_development&lt;br /&gt;
#http://jbehave.org/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language&lt;br /&gt;
#http://guides.rubyonrails.org/command_line.html&lt;br /&gt;
#http://en.wikipedia.org/wiki/Cucumber_%28software%29&lt;br /&gt;
#http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/&lt;br /&gt;
#http://pastebin.com/kJxjwSF6&lt;br /&gt;
&lt;br /&gt;
=Other Interesting Links=&lt;br /&gt;
*[http://net.tutsplus.com/tutorials/php/the-newbies-guide-to-test-driven-development/ Newbies guide to TDD]&lt;br /&gt;
*[http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial The 30 minute Regex tutorial]&lt;br /&gt;
*[http://www.andrejkoelewijn.com/wp/2008/10/27/sql-is-a-dsl/ SQL is a DSL]&lt;br /&gt;
*[https://www.relishapp.com/rspec RSpec]&lt;br /&gt;
*[https://www.relishapp.com/rspec/rspec-rails/v/2-0/docs/helper-specs/helper-spec Spec helper]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68798</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68798"/>
		<updated>2012-10-27T01:39:53Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Testing plays a major role in the software development cycle. It is a well known fact that mandatory testing of every functionality implemented be done so as to ensure that the code does not break when in production. Testing can be done in four main stages: Unit testing (individual code modules are tested for flaws and re-coded if any errors are found), Integration testing (various interacting modules are put together piece by piece to ensure that seamless integration exists among them), System testing (the system is tested as a whole after it has been fully integrated) and Acceptance testing (potential users test the system for flaws in design or execution and to see if the product matches their expectation). &lt;br /&gt;
&lt;br /&gt;
This article focuses on Unit testing by following the Test Driven Development approach for Ruby using RSpec framework as explained in this [https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu SaaS] video.&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] &amp;lt;sup&amp;gt;[http://rspec.info/]&amp;lt;/sup&amp;gt;. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by &amp;lt;sup&amp;gt;[http://jbehave.org/ JBehave]&amp;lt;/sup&amp;gt; which is another BDD testing framework [http://en.wikipedia.org/wiki/RSpec]. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host [http://en.wikipedia.org/wiki/Domain-specific_language].&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a            [http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step [http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/]. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu&lt;br /&gt;
#http://en.wikipedia.org/wiki/Software_quality_assurance &lt;br /&gt;
#http://en.wikipedia.org/wiki/Test-driven_development&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language &lt;br /&gt;
#http://en.wikipedia.org/wiki/Regular_expression&lt;br /&gt;
#http://en.wikipedia.org/wiki/SQL&lt;br /&gt;
#http://en.wikipedia.org/wiki/RSpec&lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
#http://rspec.info/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Behavior-driven_development&lt;br /&gt;
#http://jbehave.org/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language&lt;br /&gt;
#http://guides.rubyonrails.org/command_line.html&lt;br /&gt;
#http://en.wikipedia.org/wiki/Cucumber_%28software%29&lt;br /&gt;
#http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/&lt;br /&gt;
#http://pastebin.com/kJxjwSF6&lt;br /&gt;
&lt;br /&gt;
=Other Interesting Links=&lt;br /&gt;
*[http://net.tutsplus.com/tutorials/php/the-newbies-guide-to-test-driven-development/ Newbies guide to TDD]&lt;br /&gt;
*[http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial The 30 minute Regex tutorial]&lt;br /&gt;
*[http://www.andrejkoelewijn.com/wp/2008/10/27/sql-is-a-dsl/ SQL is a DSL]&lt;br /&gt;
*[https://www.relishapp.com/rspec RSpec]&lt;br /&gt;
*[https://www.relishapp.com/rspec/rspec-rails/v/2-0/docs/helper-specs/helper-spec Spec helper]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68796</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68796"/>
		<updated>2012-10-27T01:38:42Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* Other Interesting Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Testing plays a major role in the software development cycle. It is a well known fact that mandatory testing of every functionality implemented be done so as to ensure that the code does not break when in production. Testing can be done in four main stages: Unit testing (individual code modules are tested for flaws and re-coded if any errors are found), Integration testing (various interacting modules are put together piece by piece to ensure that seamless integration exists among them), System testing (the system is tested as a whole after it has been fully integrated) and Acceptance testing (potential users test the system for flaws in design or execution and to see if the product matches their expectation). &lt;br /&gt;
&lt;br /&gt;
This article focuses on Unit testing by following the Test Driven Development approach for Ruby using RSpec framework as explained in this [https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu SaaS] video.&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] [http://rspec.info/]. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/ JBehave] which is another BDD testing framework [http://en.wikipedia.org/wiki/RSpec]. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host [http://en.wikipedia.org/wiki/Domain-specific_language].&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a            [http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step [http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/]. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu&lt;br /&gt;
#http://en.wikipedia.org/wiki/Software_quality_assurance &lt;br /&gt;
#http://en.wikipedia.org/wiki/Test-driven_development&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language &lt;br /&gt;
#http://en.wikipedia.org/wiki/Regular_expression&lt;br /&gt;
#http://en.wikipedia.org/wiki/SQL&lt;br /&gt;
#http://en.wikipedia.org/wiki/RSpec&lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
#http://rspec.info/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Behavior-driven_development&lt;br /&gt;
#http://jbehave.org/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language&lt;br /&gt;
#http://guides.rubyonrails.org/command_line.html&lt;br /&gt;
#http://en.wikipedia.org/wiki/Cucumber_%28software%29&lt;br /&gt;
#http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/&lt;br /&gt;
#http://pastebin.com/kJxjwSF6&lt;br /&gt;
&lt;br /&gt;
=Other Interesting Links=&lt;br /&gt;
*[http://net.tutsplus.com/tutorials/php/the-newbies-guide-to-test-driven-development/ Newbies guide to TDD]&lt;br /&gt;
*[http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial The 30 minute Regex tutorial]&lt;br /&gt;
*[http://www.andrejkoelewijn.com/wp/2008/10/27/sql-is-a-dsl/ SQL is a DSL]&lt;br /&gt;
*[https://www.relishapp.com/rspec RSpec]&lt;br /&gt;
*[https://www.relishapp.com/rspec/rspec-rails/v/2-0/docs/helper-specs/helper-spec Spec helper]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68788</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68788"/>
		<updated>2012-10-27T01:34:29Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Testing plays a major role in the software development cycle. It is a well known fact that mandatory testing of every functionality implemented be done so as to ensure that the code does not break when in production. Testing can be done in four main stages: Unit testing (individual code modules are tested for flaws and re-coded if any errors are found), Integration testing (various interacting modules are put together piece by piece to ensure that seamless integration exists among them), System testing (the system is tested as a whole after it has been fully integrated) and Acceptance testing (potential users test the system for flaws in design or execution and to see if the product matches their expectation). &lt;br /&gt;
&lt;br /&gt;
This article focuses on Unit testing by following the Test Driven Development approach for Ruby using RSpec framework as explained in this [https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu SaaS] video.&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] [http://rspec.info/]. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/ JBehave] which is another BDD testing framework [http://en.wikipedia.org/wiki/RSpec]. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host [http://en.wikipedia.org/wiki/Domain-specific_language].&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a            [http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step [http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/]. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu&lt;br /&gt;
#http://en.wikipedia.org/wiki/Software_quality_assurance &lt;br /&gt;
#http://en.wikipedia.org/wiki/Test-driven_development&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language &lt;br /&gt;
#http://en.wikipedia.org/wiki/Regular_expression&lt;br /&gt;
#http://en.wikipedia.org/wiki/SQL&lt;br /&gt;
#http://en.wikipedia.org/wiki/RSpec&lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
#http://rspec.info/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Behavior-driven_development&lt;br /&gt;
#http://jbehave.org/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language&lt;br /&gt;
#http://guides.rubyonrails.org/command_line.html&lt;br /&gt;
#http://en.wikipedia.org/wiki/Cucumber_%28software%29&lt;br /&gt;
#http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/&lt;br /&gt;
#http://pastebin.com/kJxjwSF6&lt;br /&gt;
&lt;br /&gt;
=Other Interesting Links=&lt;br /&gt;
*[http://net.tutsplus.com/tutorials/php/the-newbies-guide-to-test-driven-development/ Newbies guide to TDD]&lt;br /&gt;
*[http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial The 30 minute Regex tutorial]&lt;br /&gt;
*[http://www.andrejkoelewijn.com/wp/2008/10/27/sql-is-a-dsl/ SQL is a DSL]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68781</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68781"/>
		<updated>2012-10-27T01:33:01Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Testing plays a major role in the software development cycle. It is a well known fact that mandatory testing of every functionality implemented be done so as to ensure that the code does not break when in production. Testing can be done in four main stages: Unit testing (individual code modules are tested for flaws and re-coded if any errors are found), Integration testing (various interacting modules are put together piece by piece to ensure that seamless integration exists among them), System testing (the system is tested as a whole after it has been fully integrated) and Acceptance testing (potential users test the system for flaws in design or execution and to see if the product matches their expectation). &lt;br /&gt;
&lt;br /&gt;
This article focuses on Unit testing by following the Test Driven Development approach for Ruby using RSpec framework as explained in this [https://www.youtube.com/watch?v=oFX1KPNRruA&amp;amp;feature=relmfu SaaS] video.&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] [http://rspec.info/]. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/ JBehave] which is another BDD testing framework [http://en.wikipedia.org/wiki/RSpec]. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host [http://en.wikipedia.org/wiki/Domain-specific_language].&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a            [http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step [http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/]. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
# http://en.wikipedia.org/wiki/Software_quality_assurance &lt;br /&gt;
#http://en.wikipedia.org/wiki/Test-driven_development&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language &lt;br /&gt;
#http://en.wikipedia.org/wiki/Regular_expression&lt;br /&gt;
#http://en.wikipedia.org/wiki/SQL&lt;br /&gt;
#http://en.wikipedia.org/wiki/RSpec&lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
#http://rspec.info/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Behavior-driven_development&lt;br /&gt;
#http://jbehave.org/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language&lt;br /&gt;
#http://guides.rubyonrails.org/command_line.html&lt;br /&gt;
#http://en.wikipedia.org/wiki/Cucumber_%28software%29&lt;br /&gt;
#http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Other Interesting Links=&lt;br /&gt;
*[http://net.tutsplus.com/tutorials/php/the-newbies-guide-to-test-driven-development/ Newbies guide to TDD]&lt;br /&gt;
*[http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial The 30 minute Regex tutorial]&lt;br /&gt;
*[http://www.andrejkoelewijn.com/wp/2008/10/27/sql-is-a-dsl/ SQL is a DSL]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68775</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68775"/>
		<updated>2012-10-27T01:29:21Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Testing plays a major role in the software development cycle. It is a well known fact that mandatory testing of every functionality implemented be done so as to ensure that the code does not break when in production. Testing can be done in four main stages: Unit testing (individual code modules are tested for flaws and re-coded if any errors are found), Integration testing (various interacting modules are put together piece by piece to ensure that seamless integration exists among them), System testing (the system is tested as a whole after it has been fully integrated) and Acceptance testing (potential users test the system for flaws in design or execution and to see if the product matches their expectation).&lt;br /&gt;
&lt;br /&gt;
This article focuses on Unit testing by following the Test Driven Development approach for Ruby using RSpec framework.&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] [http://rspec.info/]. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/ JBehave] which is another BDD testing framework [http://en.wikipedia.org/wiki/RSpec]. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host [http://en.wikipedia.org/wiki/Domain-specific_language].&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a            [http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step [http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/]. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
# http://en.wikipedia.org/wiki/Software_quality_assurance &lt;br /&gt;
#http://en.wikipedia.org/wiki/Test-driven_development&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language &lt;br /&gt;
#http://en.wikipedia.org/wiki/Regular_expression&lt;br /&gt;
#http://en.wikipedia.org/wiki/SQL&lt;br /&gt;
#http://en.wikipedia.org/wiki/RSpec&lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
#http://rspec.info/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Behavior-driven_development&lt;br /&gt;
#http://jbehave.org/&lt;br /&gt;
#http://en.wikipedia.org/wiki/Domain-specific_language&lt;br /&gt;
#http://guides.rubyonrails.org/command_line.html&lt;br /&gt;
#http://en.wikipedia.org/wiki/Cucumber_%28software%29&lt;br /&gt;
#http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Other Interesting Links=&lt;br /&gt;
*[http://net.tutsplus.com/tutorials/php/the-newbies-guide-to-test-driven-development/ Newbies guide to TDD]&lt;br /&gt;
*[http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial The 30 minute Regex tutorial]&lt;br /&gt;
*[http://www.andrejkoelewijn.com/wp/2008/10/27/sql-is-a-dsl/ SQL is a DSL]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68735</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68735"/>
		<updated>2012-10-27T01:20:21Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] [http://rspec.info/]. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/ JBehave] which is another BDD testing framework [http://en.wikipedia.org/wiki/RSpec]. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host [http://en.wikipedia.org/wiki/Domain-specific_language].&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a            [http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step [http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/]. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
=Other Interesting Links=&lt;br /&gt;
*[http://net.tutsplus.com/tutorials/php/the-newbies-guide-to-test-driven-development/ Newbies guide to TDD]&lt;br /&gt;
*[http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial The 30 minute Regex tutorial]&lt;br /&gt;
*[http://www.andrejkoelewijn.com/wp/2008/10/27/sql-is-a-dsl/ SQL is a DSL]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68734</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68734"/>
		<updated>2012-10-27T01:20:01Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] [http://rspec.info/]. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/ JBehave] which is another BDD testing framework [http://en.wikipedia.org/wiki/RSpec]. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host[http://en.wikipedia.org/wiki/Domain-specific_language].&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a            [http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step [http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/]. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
=Other Interesting Links=&lt;br /&gt;
*[http://net.tutsplus.com/tutorials/php/the-newbies-guide-to-test-driven-development/ Newbies guide to TDD]&lt;br /&gt;
*[http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial The 30 minute Regex tutorial]&lt;br /&gt;
*[http://www.andrejkoelewijn.com/wp/2008/10/27/sql-is-a-dsl/ SQL is a DSL]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68732</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68732"/>
		<updated>2012-10-27T01:19:26Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] [http://rspec.info/]. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/ JBehave] which is another BDD testing framework [http://en.wikipedia.org/wiki/RSpec]. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host.[http://en.wikipedia.org/wiki/Domain-specific_language]&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a            [http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step [http://jeffkreeftmeijer.com/2011/spec-helpers-bundler-setup-faster-rails-test-suites/]. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
=Other Interesting Links=&lt;br /&gt;
*[http://net.tutsplus.com/tutorials/php/the-newbies-guide-to-test-driven-development/ Newbies guide to TDD]&lt;br /&gt;
*[http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial The 30 minute Regex tutorial]&lt;br /&gt;
*[http://www.andrejkoelewijn.com/wp/2008/10/27/sql-is-a-dsl/ SQL is a DSL]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68721</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68721"/>
		<updated>2012-10-27T01:16:14Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby][http://rspec.info/]. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/ JBehave] which is another BDD testing framework [2]. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host.[3]&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a               [http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step[4]. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
=Also see=&lt;br /&gt;
[http://net.tutsplus.com/tutorials/php/the-newbies-guide-to-test-driven-development/ Newbies guide to TDD]&lt;br /&gt;
[http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial The 30 minute Regex tutorial]&lt;br /&gt;
[http://www.andrejkoelewijn.com/wp/2008/10/27/sql-is-a-dsl/ SQL is a DSL]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68717</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68717"/>
		<updated>2012-10-27T01:15:25Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* Features of RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby][1]. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/ JBehave] which is another BDD testing framework [2]. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host.[3]&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a               [http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step[4]. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
=Also see=&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68714</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68714"/>
		<updated>2012-10-27T01:14:31Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* RSpec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby][1]. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/ JBehave] which is another BDD testing framework [2]. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host.[3]&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a [ http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step[4]. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
=Also see=&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68712</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68712"/>
		<updated>2012-10-27T01:13:11Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby][1]. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/JBehave] which is another BDD testing framework [2]. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host.[3]&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a [ http://guides.rubyonrails.org/command_line.html Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [http://en.wikipedia.org/wiki/Cucumber_%28software%29 Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper is a file that RSpec creates as a part of the install step[4]. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. RSpec can be used to perform unit and functional testing.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
=Also see=&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68703</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68703"/>
		<updated>2012-10-27T01:08:20Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
=Characteristics of a good Unit test=&lt;br /&gt;
*'''Fast''':&lt;br /&gt;
**The tests should not take too long to run. Sometimes it would seem more logical to run only a subset of the tests (for example, when a part of the code breaks or only a particular functionality of the code is being developed). In such cases, it would not be productive if the tests take quite a bit of time to finish executing.  &lt;br /&gt;
*'''Independent''': &lt;br /&gt;
**When tests are being run, the order of execution of the tests should not matter. More importantly, tests should not be inter-dependent; which means that, it should be possible to run any subset of the test set in any order. Also, no test should be a prerequisite for another test.&lt;br /&gt;
*'''Repeatable''': &lt;br /&gt;
**The output for a test execution should be consistent irrespective of the number of times that it is run. This is essential in order to isolate bugs and enable automation. If the test notices the presence of a bug on the first run, it should do so on every consecutive run.&lt;br /&gt;
*'''Self-checking''': &lt;br /&gt;
**Testing field has changed considerably. Where [http://en.wikipedia.org/wiki/Software_quality_assurance Quality Assurance] department was involved to check the functionality of the code, it is now all automated. It is therefore, now mandatory that all tests themselves know if it is a pass or fail. No human intervention should be expected. Also, tests can run in the back all the time which means that if there is a change in the code or when the code breaks, the test script should be able to identify the same without human intervention.&lt;br /&gt;
*'''Timely''': &lt;br /&gt;
**Testing should follow the [http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development (TDD)] approach. Here, the test cases are written before the code is implemented or at least around the same time (and not after!). Hence, if the functionality of the code being tested changes, the respective test cases should change correspondingly.&lt;br /&gt;
&lt;br /&gt;
=DSL=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Domain-specific_language Domain Specific Languages] (DSLs) are small programming languages that do only a small number of activities within a specific task domain. Thus we can say that a DSL is not general. &lt;br /&gt;
Examples for DSLs include migration scripts (which are a small set of statements with the sole job of expressing changes in the database schema), [http://en.wikipedia.org/wiki/Regular_expression Regexes], [http://en.wikipedia.org/wiki/SQL SQL].&lt;br /&gt;
&lt;br /&gt;
=RSpec=&lt;br /&gt;
[http://en.wikipedia.org/wiki/RSpec RSpec] is a testing tool for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby][1]. It is based on [http://en.wikipedia.org/wiki/Behavior-driven_development Behavior Driven Development(BDD)] framework and is inspired by [http://jbehave.org/JBehave] which is another BDD testing framework [2]. RSpec is considered a DSL for writing tests. The notable difference between RSpec and SQL is that, while RSpec is an internal DSL, SQL is stand alone. Internal or embedded DSLs are implemented within another language that acts as their host.[3]&lt;br /&gt;
==Features of RSpec==&lt;br /&gt;
*Each test in RSpec is called a ''spec'' (which is short for specification).&lt;br /&gt;
*RSpec code inhabits the Spec directory which mimics the directory structure of the application.''rspec:install'' is a [Rails generator] that creates the sub-directory structure for the Spec directory. &lt;br /&gt;
*Specs are usually written for the controller and model methods. View spec checking is done mostly using the controller spec (seeing that the view will call controller method) and so, specs are usually not written for view. Instead, one can use [Cucumber] to test the view functionality.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Apps folder !! Spec folder&lt;br /&gt;
|-&lt;br /&gt;
| app/models/*.rb || spec/models/*_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
|app/controllers/ *_controller.rb || spec/controllers/ *_controller_spec.rb&lt;br /&gt;
|-&lt;br /&gt;
| app/views/*/*.html.erb || Use Cucumber&lt;br /&gt;
|}&lt;br /&gt;
User stories are taken as the input to write RSpecs. The following is an example of one such user story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
When I fill in &amp;quot;Search Posts&amp;quot; with &amp;quot;Assignments&amp;quot;&lt;br /&gt;
And I press &amp;quot;Search&amp;quot;&lt;br /&gt;
Then I should be on the Posts page with Assignment Posts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once we have the user stories ready, the next is to implement the corresponding code to realize this test case.&lt;br /&gt;
==The code we wish we had==&lt;br /&gt;
When the user clicks on the button in the view for search_posts, the controller action receives the form submission and should perform the following actions:&lt;br /&gt;
#It will call a method that searches the BackChannel App for posts with the specified search term(s)&lt;br /&gt;
#It then calls the model method to check the database to see if the entered value exists. &lt;br /&gt;
#If there is a match, a view with the Posts corresponding to the search terms is rendered. If no match is found, there should be a redirection to the homepage with an error message for the user's information.&lt;br /&gt;
The RSpec for the above mentioned scenario can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'spec_helper'&lt;br /&gt;
describe PostController do&lt;br /&gt;
  describe 'searching Posts' do&lt;br /&gt;
    it 'should call the model method that performs Post search'&lt;br /&gt;
    it 'should select the Search Results template for rendering'&lt;br /&gt;
    it 'should make the Post search results available to that template'&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spec_helper[] is a file that RSpec creates as a part of the install step. This file ensures that the functions required for  testing are loaded. The behavior of the post controller is described in the code block. The main behavior that we are focusing on is searching post. &lt;br /&gt;
In the code, ''it'' is a method that takes in a string parameter. This string describes the actions to be performed that corresponds to the specification given in the user story. Further behaviors can be added to or nested within the main describe block, or new test scripts can be written, as per requirements.&lt;br /&gt;
=Summary=&lt;br /&gt;
A good test case must adhere to the FIRST principle (Fast, Independent, Repeatable, Self-checking, Timely). TDD or Test Driven Development is the approach in which test cases are written for code even before the implementation is realized. DSLs or Domain Specific Languages take on a very specialized set of tasks. When unit tests are written using RSpec, which is an embedded DSL for Ruby testing, we usually write the tests for the controller and model methods and leave the view testing to Cucumber. The Spec files are stored in the Spec directory which mimics the application directory structure. The spec_helper file which facilitates testing, is installed with RSpec. &lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
=Also see=&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68013</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=68013"/>
		<updated>2012-10-23T16:28:45Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* Features of Unit tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
=Features of Unit tests=&lt;br /&gt;
*Fast: Run tests quickly&lt;br /&gt;
*Independent: No tests depend on other. So can run any subset of the tests in any order.&lt;br /&gt;
*Repeatable: Run N times and get the same result.&lt;br /&gt;
*Self-checking: Test can automatically detect if passed. No human checking of output should be required.&lt;br /&gt;
*Timely: Written about the same time as the code under test.&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of QA=&lt;br /&gt;
&lt;br /&gt;
=Rspec=&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
=Also see=&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=67740</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w30_an&amp;diff=67740"/>
		<updated>2012-10-22T01:20:13Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: Created page with &amp;quot;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;  =Introduction=  =Features of Unit tests=  =Disadvantages of QA=  =Rspec=  =Conclusion=  =References=...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
=Features of Unit tests=&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of QA=&lt;br /&gt;
&lt;br /&gt;
=Rspec=&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
=Also see=&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=67739</id>
		<title>CSC/ECE 517 Fall 2012</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=67739"/>
		<updated>2012-10-22T01:19:56Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE 517 Fall 2012/ch1 n xx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w1 rk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w20 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w5 su]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w6 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w4 aj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w7 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w8 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w9 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w10 pk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w12 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w14 gv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w17 ir]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w22 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 wi]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w31 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w16 br]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w23 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w24 nr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w15 rt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w3 pl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w32 cm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w37 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w67 ks]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w27 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w29 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w33 op]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w19 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w34 vd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w35 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w30 rp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w58 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w47 sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w69 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w44 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w45 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w53 kc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 ar]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w39 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w54 go]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w56 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w64 nn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w66 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w42 js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w46 sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w71 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w63 dv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w55 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w57 mp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w52 an]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch1b 1w38 nm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w60 ac]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w62 rb]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w29 st]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w30 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w17 pt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w31 up]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w9 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w19 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w16 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w8 vp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w3 jm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w23 sr]]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=67738</id>
		<title>CSC/ECE 517 Fall 2012</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=67738"/>
		<updated>2012-10-22T01:09:19Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: Undo revision 67737 by Nmanjun3 (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE 517 Fall 2012/ch1 n xx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w1 rk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w20 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w5 su]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w6 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w4 aj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w7 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w8 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w9 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w10 pk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w12 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w14 gv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w17 ir]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w22 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 wi]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w31 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w16 br]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w23 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w24 nr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w15 rt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w3 pl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w32 cm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w37 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w67 ks]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w27 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w29 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w33 op]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w19 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w34 vd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w35 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w30 rp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w58 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w47 sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w69 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w44 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w45 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w53 kc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 ar]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w39 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w54 go]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w56 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w64 nn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w66 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w42 js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w46 sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w71 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w63 dv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w55 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w57 mp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w52 an]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch1b 1w38 nm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w60 ac]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w62 rb]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w29 st]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch 2w30 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w17 pt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w31 up]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w9 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w19 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w16 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w8 vp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w3 jm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w23 sr]]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=67737</id>
		<title>CSC/ECE 517 Fall 2012</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=67737"/>
		<updated>2012-10-22T01:00:20Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE 517 Fall 2012/ch1 n xx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w1 rk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w20 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w5 su]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w6 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w4 aj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w7 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w8 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w9 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w10 pk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w12 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w14 gv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w17 ir]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w22 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 wi]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w31 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w16 br]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w23 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w24 nr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w15 rt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w3 pl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w32 cm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w37 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w67 ks]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w27 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w29 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w33 op]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w19 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w34 vd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w35 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w30 rp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w58 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w47 sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w69 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w44 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w45 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w53 kc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 ar]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w39 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w54 go]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w56 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w64 nn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w66 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w42 js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w46 sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w71 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w63 dv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w55 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w57 mp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w52 an]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch1b 1w38 nm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w60 ac]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w62 rb]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w29 st]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w30 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w17 pt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w31 up]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w9 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w19 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w16 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w8 vp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w3 jm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w23 sr]]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch_2w30_an&amp;diff=67533</id>
		<title>CSC/ECE 517 Fall 2012/ch 2w30 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch_2w30_an&amp;diff=67533"/>
		<updated>2012-10-14T19:28:20Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: Created page with &amp;quot;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;  =Introduction=  =Features of Unit tests=  =Disadvantages of QA=  =Rspec=  =Conclusion=  =References=...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 5.2 - FIRST, TDD and getting started with RSpec'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
=Features of Unit tests=&lt;br /&gt;
&lt;br /&gt;
=Disadvantages of QA=&lt;br /&gt;
&lt;br /&gt;
=Rspec=&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
=Also see=&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=67532</id>
		<title>CSC/ECE 517 Fall 2012</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=67532"/>
		<updated>2012-10-14T19:25:25Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE 517 Fall 2012/ch1 n xx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w1 rk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w20 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w5 su]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w6 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w4 aj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w7 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w8 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w9 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w10 pk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w12 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w14 gv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w17 ir]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w22 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 wi]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w31 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w16 br]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w23 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w24 nr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w15 rt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w3 pl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w32 cm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w37 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w67 ks]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w27 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w29 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w33 op]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w19 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w34 vd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w35 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w30 rp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w58 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w47 sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w69 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w44 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w45 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w53 kc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 ar]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w39 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w54 go]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w56 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w64 nn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w66 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w42 js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w46 sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w71 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w63 dv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w55 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w57 mp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w52 an]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch1b 1w38 nm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w60 ac]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w62 rb]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch 2w30 an]]&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=67521</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=67521"/>
		<updated>2012-10-12T20:14:32Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [http://en.wikipedia.org/wiki/Software_as_a_service SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It gives an overview of MVC responsibilities in a Rails application with the main focus on the creation of controllers and views for a specific model.&lt;br /&gt;
&lt;br /&gt;
=MVC responsibilities=&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* '''Model''': Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get and manipulate data. Different methods are provided by ''ActiveRecord'' to do that [1]. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''Controller''': In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods [3]. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling Movie.find. In a real application, this is unsafe and must be handled by an exception since ''params[:id]'' can happen to be a non-existing value and will result in an error. Finally the instance variable ''@movie'' in the controller is going to be available to the view.&lt;br /&gt;
&lt;br /&gt;
* '''View''':  Views are responsible for creating response in the browser to display data and allow user interaction [2][3]. In the above example, show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in ''app/view/movies/show.html.erb''. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
=Adding a new controller action to Rails application=&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ''ActionController'' super class [3]. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate ''app/controllers/*_controller.rb''. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in ''routes.rb'' &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in ''app/views/model/action.html.erb''. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the ''app/view/model''. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in ''app/view/movie/index.html.erb''. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=URI helpers=&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another [4]. In the above mentioned example of a view, there are three helper methods used namely, ''movie_path(movie)'', ''edit_movie_path(movie)'', ''new_movie_path''. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies ''index.html.erb''. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be ''movie/:id'' with a ''GET'' method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route ''GET /movies/:id'' which matches the show action of the movies controller. Further it takes '':id'' and stores as ''params[:id]''. With that ''params[:id]'', appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
[[File:Helper_methods.gif‎|700 px|thumb|center|Connecting URIs using helper methods]]&lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, ''movies_path''. ''movies_path'' with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and ''movies_path'' is a method call.&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
Implementing MVC architecture in Rails application has few advantages. For example it separates models from presentation which in turn helps in implementing better test cases and better UI's for the user [9]. It also separates controller functionality with views which facilitates development of better web interfaces. Also Rails provides an easy way to implement MVC architecture for a user. All these advantages and the fact that MVC can be implemented in an effortless and uncomplicated manner necessitate the use of MVC architecture in Rails application.   &lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#https://class.coursera.org/saas/lecture/preview/index &lt;br /&gt;
#http://en.wikibooks.org/wiki/Ruby_on_Rails/Getting_Started/Model-View-Controller&lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
#http://en.wikipedia.org/wiki/Software_as_a_service&lt;br /&gt;
#http://en.wikipedia.org/wiki/Representational_state_transfer&lt;br /&gt;
#http://en.wikipedia.org/wiki/Embedded_Ruby&lt;br /&gt;
#http://amix.dk/blog/post/19615&lt;br /&gt;
&lt;br /&gt;
=Also see=&lt;br /&gt;
#http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&lt;br /&gt;
#http://books.google.com/books?id=jMCO096qlRsC&amp;amp;printsec=frontcover&amp;amp;source=gbs_ge_summary_r&amp;amp;cad=0#v=onepage&amp;amp;q&amp;amp;f=false&lt;br /&gt;
#http://pragprog.com/book/rails4/agile-web-development-with-rails&lt;br /&gt;
#http://ruby.railstutorial.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=67520</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=67520"/>
		<updated>2012-10-12T18:08:01Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [http://en.wikipedia.org/wiki/Software_as_a_service SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It gives an overview of MVC responsibilities in a Rails application with the main focus on the creation of controllers and views for a specific model.&lt;br /&gt;
&lt;br /&gt;
=MVC responsibilities=&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* '''Model''': Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get and manipulate data. Different methods are provided by ''ActiveRecord'' to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''Controller''': In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling Movie.find. In a real application, this is unsafe and must be handled by an exception since ''params[:id]'' can happen to be a non-existing value and will result in an error. Finally the instance variable ''@movie'' in the controller is going to be available to the view.&lt;br /&gt;
&lt;br /&gt;
* '''View''':  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example, show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in ''app/view/movies/show.html.erb''. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
=Adding a new controller action to Rails application=&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ''ActionController'' super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate ''app/controllers/*_controller.rb''. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in ''routes.rb'' &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in ''app/views/model/action.html.erb''. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the ''app/view/model''. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in ''app/view/movie/index.html.erb''. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=URI helpers=&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, ''movie_path(movie)'', ''edit_movie_path(movie)'', ''new_movie_path''. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies ''index.html.erb''. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be ''movie/:id'' with a ''GET'' method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route ''GET /movies/:id'' which matches the show action of the movies controller. Further it takes '':id'' and stores as ''params[:id]''. With that ''params[:id]'', appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
[[File:Helper_methods.gif‎|700 px|thumb|center|Connecting URIs using helper methods]]&lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, ''movies_path''. ''movies_path'' with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and ''movies_path'' is a method call.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#https://class.coursera.org/saas/lecture/preview/index &lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
#http://en.wikipedia.org/wiki/Software_as_a_service&lt;br /&gt;
#http://en.wikipedia.org/wiki/Representational_state_transfer&lt;br /&gt;
#http://en.wikipedia.org/wiki/Embedded_Ruby&lt;br /&gt;
#http://pragprog.com/book/rails4/agile-web-development-with-rails&lt;br /&gt;
#http://ruby.railstutorial.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66976</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66976"/>
		<updated>2012-10-04T01:05:26Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* MVC responsibilities */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [http://en.wikipedia.org/wiki/Software_as_a_service SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
=MVC responsibilities=&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* '''Model''': Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get and manipulate data. Different methods are provided by ''ActiveRecord'' to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''Controller''': In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since ''params[:id]'' can happen to be a non-existing value and will result in an error. Finally the instance variable ''@movie'' in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
* '''View''':  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in ''app/view/movies/show.html.erb''. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
=Adding a new controller action to Rails application=&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ''ActionController'' super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate ''app/controllers/*_controller.rb''. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in ''routes.rb'' &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in ''app/views/model/action.html.erb''. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the ''app/view/model''. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in ''app/view/movie/index.html.erb''. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=URI helpers=&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, ''movie_path(movie)'', ''edit_movie_path(movie)'', ''new_movie_path''. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies ''index.html.erb''. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be ''movie/:id'' with a ''GET'' method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route ''GET /movies/:id'' which matches the show action of the movies controller. Further it takes '':id'' and stores as ''params[:id]''. With that ''params[:id]'', appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
[[File:Helper_methods.gif‎|700 px|thumb|center|Connecting URIs using helper methods]]&lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, ''movies_path''. ''movies_path'' with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and ''movies_path'' is a method call.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#https://class.coursera.org/saas/lecture/preview/index &lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
#http://en.wikipedia.org/wiki/Software_as_a_service&lt;br /&gt;
#http://en.wikipedia.org/wiki/Representational_state_transfer&lt;br /&gt;
#http://en.wikipedia.org/wiki/Embedded_Ruby&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66969</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66969"/>
		<updated>2012-10-04T01:03:41Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [http://en.wikipedia.org/wiki/Software_as_a_service SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
=MVC responsibilities=&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* '''Model''': Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get and manipulate data. Different methods are provided by ''ActiveRecord'' to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''Controller''': In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since ''params[:id]'' can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
* '''View''':  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in ''app/view/movies/show.html.erb''. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
=Adding a new controller action to Rails application=&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ''ActionController'' super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate ''app/controllers/*_controller.rb''. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in ''routes.rb'' &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in ''app/views/model/action.html.erb''. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the ''app/view/model''. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in ''app/view/movie/index.html.erb''. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=URI helpers=&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, ''movie_path(movie)'', ''edit_movie_path(movie)'', ''new_movie_path''. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies ''index.html.erb''. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be ''movie/:id'' with a ''GET'' method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route ''GET /movies/:id'' which matches the show action of the movies controller. Further it takes '':id'' and stores as ''params[:id]''. With that ''params[:id]'', appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
[[File:Helper_methods.gif‎|700 px|thumb|center|Connecting URIs using helper methods]]&lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, ''movies_path''. ''movies_path'' with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and ''movies_path'' is a method call.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#https://class.coursera.org/saas/lecture/preview/index &lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
#http://en.wikipedia.org/wiki/Software_as_a_service&lt;br /&gt;
#http://en.wikipedia.org/wiki/Representational_state_transfer&lt;br /&gt;
#http://en.wikipedia.org/wiki/Embedded_Ruby&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66947</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66947"/>
		<updated>2012-10-04T00:58:13Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [http://en.wikipedia.org/wiki/Software_as_a_service SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
=MVC responsibilities=&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* '''Model''': Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get and manipulate data. Different methods are provided by ''''ActiveRecord'''' to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''Controller''': In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since ''''params[:id]'''' can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
* '''View''':  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in ''''app/view/movies/show.html.erb''''. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
=Adding a new controller action to Rails application=&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ''''ActionController'''' super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate ''''app/controllers/*_controller.rb''''. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in ''''routes.rb'''' &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in ''''app/views/model/action.html.erb''''. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the ''''app/view/model''''. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in ''''app/view/movie/index.html.erb''''. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=URI helpers=&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, ''''movie_path(movie)'''', ''''edit_movie_path(movie)'''', ''''new_movie_path''''. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies ''''index.html.erb''''. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be ''''movie/:id'''' with a ''''GET'''' method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route ''''GET /movies/:id'''' which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
[[File:Helper_methods.gif‎|700 px|thumb|center|Connecting URIs using helper methods]]&lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, ''''movies_path''''. ''''movies_path'''' with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and ''''movies_path'''' is a method call.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#https://class.coursera.org/saas/lecture/preview/index &lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
#http://en.wikipedia.org/wiki/Software_as_a_service&lt;br /&gt;
#http://en.wikipedia.org/wiki/Representational_state_transfer&lt;br /&gt;
#http://en.wikipedia.org/wiki/Embedded_Ruby&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66930</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66930"/>
		<updated>2012-10-04T00:53:59Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* MVC responsibilities */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [http://en.wikipedia.org/wiki/Software_as_a_service SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
=MVC responsibilities=&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* '''Model''': Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''Controller''': In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
* '''View''':  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
=Adding a new controller action to Rails application=&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=URI helpers=&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
[[File:Helper_methods.gif‎|700 px|thumb|center|Connecting URIs using helper methods]]&lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#https://class.coursera.org/saas/lecture/preview/index &lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
#http://en.wikipedia.org/wiki/Software_as_a_service&lt;br /&gt;
#http://en.wikipedia.org/wiki/Representational_state_transfer&lt;br /&gt;
#http://en.wikipedia.org/wiki/Embedded_Ruby&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66924</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66924"/>
		<updated>2012-10-04T00:51:35Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [http://en.wikipedia.org/wiki/Software_as_a_service SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
=MVC responsibilities=&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
=Adding a new controller action to Rails application=&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=URI helpers=&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
[[File:Helper_methods.gif‎|700 px|thumb|center|Connecting URIs using helper methods]]&lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#https://class.coursera.org/saas/lecture/preview/index &lt;br /&gt;
#http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
#http://en.wikipedia.org/wiki/Software_as_a_service&lt;br /&gt;
#http://en.wikipedia.org/wiki/Representational_state_transfer&lt;br /&gt;
#http://en.wikipedia.org/wiki/Embedded_Ruby&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66904</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66904"/>
		<updated>2012-10-04T00:44:34Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
=MVC responsibilities=&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
[[File:Helper_methods.gif‎|700 px|thumb|center|Connecting URIs using helper methods]]&lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66221</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66221"/>
		<updated>2012-10-03T03:09:42Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* URI helpers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
[[File:Helper_methods.gif‎|700 px|thumb|center|Connecting URIs using helper methods]]&lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66220</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66220"/>
		<updated>2012-10-03T03:08:59Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* URI helpers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
[[File:Helper_methods.gif‎|700 px|thumb|Connecting URIs using helper methods]]&lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Helper_methods.gif&amp;diff=66219</id>
		<title>File:Helper methods.gif</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Helper_methods.gif&amp;diff=66219"/>
		<updated>2012-10-03T03:07:46Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: helper methods&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;helper methods&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66209</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66209"/>
		<updated>2012-10-03T02:44:33Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* URI helpers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
[[File:Helper_methods.png‎|700 px|thumb|right|Connecting URIs using helper methods]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66208</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66208"/>
		<updated>2012-10-03T02:42:43Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* URI helpers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[File:Helper_methods.png‎|700 px|thumb|right|Connecting URIs using helper methods]]&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66207</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66207"/>
		<updated>2012-10-03T02:41:35Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* URI helpers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Helper_methods.png‎|700 px|thumb|right|Connecting URIs using helper methods]]&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66203</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66203"/>
		<updated>2012-10-03T02:38:28Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* URI helpers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
[[File:Helper_methods.png‎|700 px|thumb|right|Connecting URIs using helper methods &amp;lt;ref name=&amp;quot;https://www.youtube.com/watch?v=zy7P0E9gs-E&amp;quot; /&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66202</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66202"/>
		<updated>2012-10-03T02:38:04Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
[[File:Helper_methods.png‎|200 px|thumb|right|Connecting URIs using helper methods &amp;lt;ref name=&amp;quot;https://www.youtube.com/watch?v=zy7P0E9gs-E&amp;quot; /&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66201</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66201"/>
		<updated>2012-10-03T02:37:43Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* URI helpers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
[[File:Helper_methods.png‎|200 px|thumb|right|Connecting URIs using helper methods &amp;lt;ref name=&amp;quot;https://www.youtube.com/watch?v=zy7P0E9gs-E&amp;quot; /&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Infobox Algorithm&lt;br /&gt;
|class=[[Sorting algorithm]]&lt;br /&gt;
|image=[[File:Merge-sort-example-300px.gif]]&lt;br /&gt;
|caption=An example of merge sort. First divide the list into the smallest unit (1 element), then compare each element with the adjacent list to sort and merge the two adjacent lists. Finally all the elements are sorted and merged.&lt;br /&gt;
|data=[[Array data structure|Array]]&lt;br /&gt;
|time=O(''n'' log ''n'')&lt;br /&gt;
|best-time=O(''n'' log ''n'') typical,&lt;br /&gt;
O(''n'') natural variant&lt;br /&gt;
|average-time=O(''n'' log ''n'')&lt;br /&gt;
|space=O(''n'') auxiliary&lt;br /&gt;
|optimal=Yes&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Helper_methods.png&amp;diff=66200</id>
		<title>File:Helper methods.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Helper_methods.png&amp;diff=66200"/>
		<updated>2012-10-03T02:31:44Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: uploaded a new version of &amp;amp;quot;File:Helper methods.png&amp;amp;quot;: Edit&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Helper methods&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Helper_methods.png&amp;diff=66199</id>
		<title>File:Helper methods.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Helper_methods.png&amp;diff=66199"/>
		<updated>2012-10-03T02:29:31Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: Helper methods&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Helper methods&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66196</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66196"/>
		<updated>2012-10-03T02:20:00Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Infobox Algorithm&lt;br /&gt;
|class=[[Sorting algorithm]]&lt;br /&gt;
|image=[[File:Merge-sort-example-300px.gif]]&lt;br /&gt;
|caption=An example of merge sort. First divide the list into the smallest unit (1 element), then compare each element with the adjacent list to sort and merge the two adjacent lists. Finally all the elements are sorted and merged.&lt;br /&gt;
|data=[[Array data structure|Array]]&lt;br /&gt;
|time=O(''n'' log ''n'')&lt;br /&gt;
|best-time=O(''n'' log ''n'') typical,&lt;br /&gt;
O(''n'') natural variant&lt;br /&gt;
|average-time=O(''n'' log ''n'')&lt;br /&gt;
|space=O(''n'') auxiliary&lt;br /&gt;
|optimal=Yes&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66195</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66195"/>
		<updated>2012-10-03T02:13:43Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Infobox Algorithm&lt;br /&gt;
|class=[[Sorting algorithm]]&lt;br /&gt;
|image=[[File:Merge-sort-example-300px.gif]]&lt;br /&gt;
|caption=An example of merge sort. First divide the list into the smallest unit (1 element), then compare each element with the adjacent list to sort and merge the two adjacent lists. Finally all the elements are sorted and merged.&lt;br /&gt;
|data=[[Array data structure|Array]]&lt;br /&gt;
|time=O(''n'' log ''n'')&lt;br /&gt;
|best-time=O(''n'' log ''n'') typical,&lt;br /&gt;
O(''n'') natural variant&lt;br /&gt;
|average-time=O(''n'' log ''n'')&lt;br /&gt;
|space=O(''n'') auxiliary&lt;br /&gt;
|optimal=Yes&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66194</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66194"/>
		<updated>2012-10-03T02:13:07Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Infobox Algorithm&lt;br /&gt;
|class=[[Sorting algorithm]]&lt;br /&gt;
|image=[[File:Merge-sort-example-300px.gif]]&lt;br /&gt;
|caption=An example of merge sort. First divide the list into the smallest unit (1 element), then compare each element with the adjacent list to sort and merge the two adjacent lists. Finally all the elements are sorted and merged.&lt;br /&gt;
|data=[[Array data structure|Array]]&lt;br /&gt;
|time=O(''n'' log ''n'')&lt;br /&gt;
|best-time=O(''n'' log ''n'') typical,&lt;br /&gt;
O(''n'') natural variant&lt;br /&gt;
|average-time=O(''n'' log ''n'')&lt;br /&gt;
|space=O(''n'') auxiliary&lt;br /&gt;
|optimal=Yes&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[File:Ruby.jpg]]&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66191</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66191"/>
		<updated>2012-10-03T02:05:15Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* URI helpers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Infobox Algorithm&lt;br /&gt;
|class=[[Sorting algorithm]]&lt;br /&gt;
|image=[[File:Merge-sort-example-300px.gif]]&lt;br /&gt;
|caption=An example of merge sort. First divide the list into the smallest unit (1 element), then compare each element with the adjacent list to sort and merge the two adjacent lists. Finally all the elements are sorted and merged.&lt;br /&gt;
|data=[[Array data structure|Array]]&lt;br /&gt;
|time=O(''n'' log ''n'')&lt;br /&gt;
|best-time=O(''n'' log ''n'') typical,&lt;br /&gt;
O(''n'') natural variant&lt;br /&gt;
|average-time=O(''n'' log ''n'')&lt;br /&gt;
|space=O(''n'') auxiliary&lt;br /&gt;
|optimal=Yes&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66190</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66190"/>
		<updated>2012-10-03T02:02:46Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &amp;lt;/br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call. &lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Infobox Algorithm&lt;br /&gt;
|class=[[Sorting algorithm]]&lt;br /&gt;
|image=[[File:Merge-sort-example-300px.gif]]&lt;br /&gt;
|caption=An example of merge sort. First divide the list into the smallest unit (1 element), then compare each element with the adjacent list to sort and merge the two adjacent lists. Finally all the elements are sorted and merged.&lt;br /&gt;
|data=[[Array data structure|Array]]&lt;br /&gt;
|time=O(''n'' log ''n'')&lt;br /&gt;
|best-time=O(''n'' log ''n'') typical,&lt;br /&gt;
O(''n'') natural variant&lt;br /&gt;
|average-time=O(''n'' log ''n'')&lt;br /&gt;
|space=O(''n'') auxiliary&lt;br /&gt;
|optimal=Yes&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66189</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66189"/>
		<updated>2012-10-03T02:00:15Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another. In the above mentioned example of a view, there are three helper methods used namely, movie_path(movie),edit_movie_path(movie), new_movie_path. More examples are shown below in the table.   &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following example illustrates how the helper methods work. Lets consider that the user is looking at the list of all movies index.index.html.erb. Somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that sets up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From here, once the URI is hit, the controller looks up for this URI in the routing subsystem. This corresponds to the Restful route GET /movies/:id which matches the show action of the movies controller. Further it takes :id and stores as params[:id]. With that params[:id], appropriate controller action is called. &amp;lt;/br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Further the user can return to the list of movies with the help of another URI helper, movies_path. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here Back to List is the text that is click-able and movies_path is a method call. &lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66187</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w64 nn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w64_nn&amp;diff=66187"/>
		<updated>2012-10-03T01:40:39Z</updated>

		<summary type="html">&lt;p&gt;Nmanjun3: /* Adding a new controller action to Rails application */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;''' SaaS - 3.12 Controller and views'''&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://class.coursera.org/saas/lecture/preview/index Coursera] is a technology company that provides free online education by making videos. [https://class.coursera.org/saas/lecture/preview/index SaaS] is one such video series made by University of California, Berkley.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This article focuses on the concepts and usage of controllers and views in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] application which is available as one of the [https://www.youtube.com/watch?v=zy7P0E9gs-E SaaS video] lectures. It covers the general information on model, view and controllers in a Rails application.&lt;br /&gt;
&lt;br /&gt;
==MVC responsibilities==&lt;br /&gt;
In Rails, applications are broken into three types of components: models, views, and controllers.&lt;br /&gt;
&lt;br /&gt;
* Model: Application's state is maintained by models. It not only stores the state of the application in databases but also imposes business rules on that data. It contains methods to get/manipulate data. Different methods are provided by ActiveRecord to do that. An example is shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Movie &amp;lt; ActiveRecord::Base&lt;br /&gt;
  belongs_to :genre  &lt;br /&gt;
  has_many :actor  &lt;br /&gt;
&lt;br /&gt;
  def find_movie_name(movie_id)&lt;br /&gt;
    if movie_id then&lt;br /&gt;
      movie = Movie.find_by_id(movie_id)      &lt;br /&gt;
      return movie.name      &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Controller: In [http://en.wikipedia.org/wiki/Representational_state_transfer REST] applications, the controller acts as a middle man to synchronize the communication between model and view. It is responsible for receiving request from the user, getting data from the model and making it available to the view for displaying data to the user. Controllers are also responsible for routing the requests to internal actions. This is facilitated by helper methods. An example is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def show&lt;br /&gt;
    @movie = Movie.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here params is the parameter from the request that is parsed out by the routing subsystem. This contains the id of the movie that the user wants to find which can be fetched by calling movie.find. In a real application this is unsafe and must be handled by an exception since params[:id] can happen to be a non-existing value and will result in an error. Finally the instance variable @movie in the controller is going to be available to the view. &lt;br /&gt;
&lt;br /&gt;
*View:  Views are responsible for creating response in the browser to display data and allow user interaction. In the above example Show is going to display the details of a movie (genre, actors). To select the view for the rendering step, the default action the rails will take is, to find a view whose directory name matches the name of its class which is movies and finally matches the name of that particular action i.e show. Thus the view for the above action can be found in app/view/movies/show.html.erb. Here ERb ( [http://en.wikipedia.org/wiki/Embedded_Ruby Embedded Ruby]) is used to generate dynamic content in Rails application.&lt;br /&gt;
&lt;br /&gt;
==Adding a new controller action to Rails application==&lt;br /&gt;
In Rails controller forms the logical center of the application. Controller is essentially a Ruby class is inherited from ActionController super class. To create a controller, these steps must be followed.  &lt;br /&gt;
* Add the action method in the appropriate app/controllers/*_controller.rb. This method will have the actual code to do whatever the action is meant to do. For example,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def new&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the new function creates an instance of Movies controller.&lt;br /&gt;
* Create a route in config/routes.rb. When the application receives a request from the user, it is this route that determines the appropriate controller and action to run. Example of a route in routes.rb &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
match 'movies/new' =&amp;gt; 'movies#new'&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
* Ensure there is something for the action to render in app/views/model/action.html.erb. Every trip through the controller has to end with returning something to the view. Even if there is no explicit render at the end of controller, by default, Rails looks for that particular action in the app/view/model. For example, the controller shown below has an index method as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MoviesController &amp;lt; ApplicationController&lt;br /&gt;
  def index&lt;br /&gt;
    @movies = Movie.all&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The view for this controller will be found in app/view/movie/index.html.erb. It is shown below as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Listing Movies&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;% @movies.each do |movie| %&amp;gt;&lt;br /&gt;
  &amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.title %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= movie.description %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Show', movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Edit', edit_movie_path(movie) %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;%= link_to 'Remove', movie, :confirm =&amp;gt; 'Are you sure?', :method =&amp;gt; :delete %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
  &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;%= link_to 'New movie', new_movie_path %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==URI helpers==&lt;br /&gt;
&lt;br /&gt;
The routing subsystem that maps the URI to different controller actions also provides helper methods that generates routes in the context of that page. These routes generated by helper classes is used by the user in the views to navigate from one page to another.  &lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper method !! URI returned !! RESTful route !! Action&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || GET /movies || index&lt;br /&gt;
|-&lt;br /&gt;
| movies_path || /movies || POST /movies || create&lt;br /&gt;
|-&lt;br /&gt;
| new_movie_path || /movies/new || GET /movies/new || new&lt;br /&gt;
|-&lt;br /&gt;
| edit_movie_path(m) || /movies/1/edit || GET /movies/:id/edit || edit&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || GET /movies/:id || show&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || PUT /movies/:id || update&lt;br /&gt;
|-&lt;br /&gt;
| movie_path(m) || /movies/1 || DELETE /movies/:id || destroy&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Just like the routing subsystem allows us to map http methods and URI's to different control actions, the same routing subsystem also sets up these helpful methods that will generate the routes in the context of the page. Example when we are looking at the list of all movies index.index.html.haml, somewhere on that page there will be a link whose argument is movie_path with an argument.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to movie_path(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
movie_path is the helper that set up and gives back a route to the show action for that movie id. So when the user clicks on it, the URI that is going to be generated is going to be movie/:id with a GET method because its a link. This is how it looks in the actual html.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;/movies/3&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
From here, once the URI is hit, that is going to get looked up in the routing subsystem. /movies/something matches the show action of the movies controller and it will take the wild card thing :id and puts that in params[:id]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GET /movies/:id&lt;br /&gt;
{:action=&amp;gt;&amp;quot;show&amp;quot;, :controller=&amp;gt;&amp;quot;movies&amp;quot;}&lt;br /&gt;
params[:id]&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
With that appropriate controller action is called&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def show&lt;br /&gt;
  @movie = Movie.find(params[:id])&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here the controller action can reasonably expect to find that params[:id] will be whatever this route said that it should match.&lt;br /&gt;
We can let the user return a list of all movies. We can use RESTful URI helpers. Here it is the index action. movies_path with no arguments links to the index action. The line to add on show template is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
link_to 'Back to List', movies_path&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Back to List is the text that is click-able and movies_path is a method call.&lt;br /&gt;
As the app gets more complicate, these mechanism scale very nicely&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
#https://www.youtube.com/watch?v=zy7P0E9gs-E&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;br /&gt;
#http://guides.rubyonrails.org/&lt;/div&gt;</summary>
		<author><name>Nmanjun3</name></author>
	</entry>
</feed>