 |
The pieces of the Model-View-Controller (MVC) architecture in Ruby on Rails are as follows:
Ruby on Rails - Model
In object-oriented, database-driven MVC web applications, Model consists of the classes representing RDBMS tables.
In Ruby On Rails, Model classes are handled through the Active Record. Usually, all the programmer needs to do is to subclass the ActiveRecord::Base class, and the program will automatically figure out which RDBMS table to use and what columns the table has. Relationships between tables are specified with simple commands.
Ruby on Rails - View
In MVC, View is the display logic, or how the data from the Controller classes is displayed. In web applications, this frequently consists of a minimal amount of code, interspersed in HTML.
There are currently many ways the views can be handled – the underlying view code is part of the Action Pack. The method in Rails itself is to use Embedded Ruby (.rhtml files), which are basically fragments of HTML with some Ruby code interspersed, with syntax quite similar to JSP. HTML and XML can also be constructed programmatically with Builder or through Liquid template system.
For each method in the controller that needs to display user output, a small HTML code fragment needs to be written. The page layout is described separately from the controller action that displays layouts, and the fragments can also call other fragments.
Ruby on Rails - Controller
In MVC, Controller classes respond to user interaction and call the application logic, which in turn manipulates the data in Model and displays the data through View. In web-based MVC applications, the Controller methods are initiated by the user through the web browser.
Controller implementation is handled through Rails' Action Pack, which has class ApplicationController. Rails applications simply subclass ApplicationController and write required actions as methods, which can then be accessed through the web, typically in form of /example/method, which calls ExampleController#method, and presents the data using the view file /app/views/example/method.rhtml, unless the method redirects elsewhere.
Rails also provides out-of-the-box scaffolding, which can quickly construct most of the logic and views needed to do common operations, such as CRUD.
Other related archives2005, 43 Things, Action Mailer, Active Record, Ajax, Apache, CGI, CRUD, DB2, David Heinemeier Hansson, December 13, FastCGI, Instiki, JSP, JavaScript,
 Adapted from the Wikipedia article "Rails' MVC architecture", under the G.N U Free Docmentation License. Please also see http://en.wikipedia.org/wiki/Main_Page |