Skip to Content
Ruby on Rails® for Microsoft Developers
book

Ruby on Rails® for Microsoft Developers

by Antonio Cangiano
April 2009
Intermediate to advanced content levelIntermediate to advanced
479 pages
12h 55m
English
Wrox
Content preview from Ruby on Rails® for Microsoft Developers

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ruby on Rails™ 3 Tutorial: Learn Rails™ by Example

Ruby on Rails™ 3 Tutorial: Learn Rails™ by Example

Michael Hartl

Publisher Resources

ISBN: 9780470374955Purchase book