2. 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.
c 2011-13 G.L. Heileman Module 5, Lecture 8 2 / 4
3. MVC Interactions in Rails
1 The browser sends a request to the web server.
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.
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.
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 neededc 2011-13 G.L. Heileman Module 5, Lecture 8 3 / 4
4. MVC Interactions in Rails
Browser
Web Server
Routes
Dispatcher
Controller
Model View
1
2
http://localhost:3000/posts
PostsController::index
3 @posts = Post.all 5 @posts
4 Post array
8 text/html
6 index.html.erb
resources :posts
7 application.html.erb
+ index.html
(response)(GET request)
c 2011-13 G.L. Heileman Module 5, Lecture 8 4 / 4