5.6. Analyzing the View Layer

So far you have analyzed the model and the controller, now let's complete the MVC triad. The files constituting the view layer are all enclosed within folders located in app\views as shown in Figure 5-9.

Figure 5.9. Figure 5-9

As you can see, inside app\views are two folders, articles and layouts. The articles folder is there to contain all the view templates and partials that are associated with the Articles controller.

Notice how each of the view files generated by the scaffold generator has the format name.html.erb. This indicates that ERb should be used as a template engine to produce HTML.

The layouts folder hosts, as the name implies, layouts. Rails knows by convention that the ArticlesController should render the layout app\views\layouts\articles.html.erb. This convention can of course be overwritten and you could, for example, decide to reuse the same layout for multiple controllers.

5.6.1. Rails' Layouts vs. ASP.NET's Master Pages

There is a striking similarity between ASP.NET's master pages and Rails' layouts. Both are aimed at sharing the same layout, structure, and style among pages that should have a similar look and feel. The first benefit in both cases is therefore the ability to automatically obtain a consistent style and structure for all the pages that are supposed to have a specific theme.

Both Rails' layout and ASP.NET's master ...

Get Ruby on Rails® for Microsoft Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.