A of the Operation of The -- Pattern in a Rails-Based Web Server January 10, 2011 v 0.4
Responding to a page request 2
A -- user clicks a link to a pattern page in on a web a web application. server January 3, 2011 clicks link Page 1 requests resource from DNS (Domain Name System) parses the URL and routes request to the server. http://domain.com/resource/action/argument 3
The -- web server receives pattern the request on a web URL server (Universal Resource Location). Rails January 3, 2011 uses a routes file to match the URL with a controller action. Page 1 passes request to activates a The routes file contains a list of URL patterns. Each pattern maps to a resource and action. One conventional URL pattern has a server resource, an action to be taken on the resource, and arguments for the action, separated by slashes: http://domain.com/resource/action/argument More on resources later. 4
The -- invoked controller action pattern requests on a web data server from a model. The January 3, model 2011 queries the database and hands data back to the controller. Page 1 requests data from a passes data to queries passes data to 5
The -- controller action then pattern passes on data a web to server a corresponding view. The January 3, view 2011 uses the data and a template to compose a page. Page 1 Don t mistake the view, a template, and a page. It may help to think of the view as page composer. Rails includes the page composer. Developers make templates. The view uses a template to compose a page. renders page from template and passes it to passes data to (Page renderer) 6
The -- controller passes the pattern complete on a page web server to the web server. January 3, 2011 Page 1 passes page to 7
The -- web server serves the pattern page on to a the web browser. server The January 3, browser 2011 renders the new page in place of the first one. Page 2 replaces Page 1 displayed for serves page to 8
Ruby -- on Rails provides pattern a framework on a web for this server MVC flow. It January enables 3, 2011 developers to work on what makes their apps unique rather than spend time re-implementing conventions. clicks link displayed for Page requests resource from serves page to passes request to passes page to activates a requests data from a queries passes data to passes data to passes data to renders page from template and passes it to 9
Developers -- write components pattern in on a a variety web server of languages. January 3, 2011 Page Composed of HTML/CSS/JavaScript E.g. Firefox, Chrome, Safari E.g. Apache Written in Rails routing DSL (Domain Specific Language) Written in Ruby language Written in Ruby language Templates written in Ruby and HTML. s compose templates into pages which link to CSS and JavaScript. E.g. MySQL 10
A -- model with a controller pattern and a on route a web is called servera resource. January 3, 2011 Resources are named with nouns. In a health-related application you may find resources such as: Person Vital Page Goal Prescription Person Resource 11
Attributes -- (or data) of a pattern resource on are a web accessed serverthrough the model. Attributes January 3, 2011 (model methods) are also named with nouns. A person model may have methods such as: Person.date_of_birth Person.height Person.gender Person.allergies Page Person Resource Person 12
Actions -- available to a resource pattern on are a accessed web server through the controller. Actions January 3, 2011 (controller methods) are named with verbs. s typically have one or more standard methods such as: Person.create Person.show Person.update Person.destroy Page Person Resource Person Person 13
Resource -- actions may be pattern visualized on a web in a page, serverfrom a view template. Names January 3, 2011of view templates correspond to controller methods. Templates corresponding to standard controller methods are: person/create.html.erb person/show.html.erb person/update.html.erb person/destroy.html.erb Page Person Resource Person Person person/show.html.erb 14
Responding to an AJAX request 15
Early web applications sent a page from the server after every user interaction. Now, using AJAX (Asynchronous JavaScript and XML) techniques, it is possible to send and receive data and fragments of pages, increasing responsiveness. AJAX involves sending or requesting data from a server asynchronously in the background while the user may continue to interact with the page. The page may be altered when the server responds. (The page also caches some data locally anticipating possible user interactions.)
A -- user action triggers a pattern request on for a additional web server data from a server. January 3, 2011 clicks link Page 1 requests resource from 17
In -- the same way a page pattern request on is a processed, web server the January web 3, 2011 server uses route definitions to pass the data request to the appropriate controller action. Page passes request to activates a 18
The -- controller requests pattern data from on a model. web server The January 3, model 2011 queries the database and hands data back to the controller. Page requests data from a queries passes data to passes data to 19
Rather -- than rendering a pattern page via on a a view, web server the January controller 3, 2011 formats the data as XML or JSON (JavaScript Object Notation) and hands it to the web server. Page formats data for 20
The -- web server s response pattern is rendered on a web in server the current page. January 3, 2011 Page 1 updated displayed for serves data to 21