Ruby on Rails

In Rails, the following classes support the MVC design pattern:

  • Model – The ActiveRecord class, described previously, implements object-relational mappings (ORM).
  • View – Views and controllers are actually bundled together in Rails in Action Pack. Dynamic content is generated by templates containing embedded Ruby (ERb) code supported by the ActionView class.
  • Controller – The ActionController class is the core of a web request in Rails. It consists of one or more actions that are executed on request and then either render a template or redirect to another action. An action is defined as a public method on the controller, which will automatically be made accessible to the web-server through Rails Routes.

MVC Interactions in Rails

Example 1:
  • 1 The browser sends a request to the web server.
  • 2 The web server processes the request, determines which route it belongs to and dispatches that request to the corresponding controller method.
Example 2:
  • 1 The browser sends a request to the web server.
  • 2 The web server processes the request, determines which route it belongs to and dispatches that request to the corresponding controller method.
  • 3 The controller asks the model layer for all of the information needed to complete the request.
Example 3:
  • 1 The browser sends a request to the web server.
  • 2 The web server processes the request, determines which route it belongs to and dispatches that request to the corresponding controller method.


MVC Implementation in Rails