Continuing our discussion of Ruby-on-Rails, this article covers the basic services provided by the ActionView. The ActionView helps you present data to your users. Keep reading to learn some terminology and study an example application.
Understanding Action Views in Ruby-on-Rails (Page 1 of 4 )
In MVC based architecture, it is the responsibility of the View component to present the data to the user in a way that is "palatable" to the user, abstracting out the unnecessary details. In other words, any framework implementing and supporting the MVC pattern should provide for the easier methods of abstraction and presentation of the required data. RoR is also a framework implementing the MVC pattern. It provides the View component as a part of ActionPack. The functionalities of the View component are encapsulated within the ActionView package.
In this discussion, I will be focusing on the basic services provided by ActionView. In the first section the focus will be on the common terminology associated with the View component. In the second and third sections, I will discuss the ActionView of RoR. And in the last section, the theory of the second and third sections will be put into practice as an application. So without much ado, let's get started.
View Component Terminology
The View component is all about presenting the data to the user. Hence the terminology associated with the View component deals more with how to present than what to present. The idea of "what to present" provides formatting and design guidelines. The main terms used in the context of View are:
Template
Layout
Pagination
There are other terms used in the context of View but the above three are the most commonly used.
Template:
By definition, a template is “A document or a file having a preset format, used as a starting point for a particular application so that format does not have to be recreated each time it is used.” That means a template contains formatting information that is often required, such as layout and place holders for the dynamic or context specific data. The best example of a template is a letter template provided by any word processing application. In the context of a web application, any of the free login/email templates in HTML format is an example of a template.
Layout:
In terms of software (web or desktop), layout means an "arrangement of GUI elements,” which means layout controls how the GUI elements (such as buttons, textboxes, and so forth) are placed within a template and in relation to each other. For example, in a registration form, the layout can be horizontal, that is the widgets (GUI elements) are placed horizontally; vertical; or both.
Pagination:
Pagination is the process of decomposing a large table into a number of smaller "pages." This comes in handy when the data to be presented in the table format is huge. The origin of pagination was in print media. However, the term found a place in web development when the requirement for decomposing the data came up. Though pagination is a neat way to present a large amount of data in a orderly manner, along with it comes problems associated with navigation, links, and so forth.
Apart from the above mentioned terms, there are others such as forms, resource links, and so on that are associated with the View component. However, the above three are more conceptually inclined than the ones mentioned later. The next question is, how are these associated with ActionView? And that is the focus of the next two sections.