O'Reilly logo

Rails Cookbook by Rob Orsini

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Action View

Introduction

Action View serves as the presentation or view layer of the MVC (model view controller) pattern. This means that it’s the component responsible for handling the presentation details of your Rails applications. Incoming requests are routed to controllers which, in turn, render view templates. View templates can dynamically create presentable output based on data structures available to them via their associated controllers. It’s in this dynamic presentation that Action View really helps to separate the details of presentation from the core business logic of your application.

Rails ships with three different types of view templating systems. The template engine that’s used for a particular request is determined by the file extension of the template file being rendered. These three templating systems, and the file extensions that trigger their execution, are: ERb templates (*.rhtml), Builder::XmlMarkup templates (*.rxml), and JavaScriptGenerator or RJS templates (*.rjs).

ERb templates are most commonly used to generate the HTML output of a Rails application; they are also used to generate email messages (though I won’t discuss that until Chapter 9, Action Mailer). They consist of files ending with the .rhtml file extension. ERb templates contain a mixture of HTML and plain text along with special ERb tags that embed Ruby into the templates, such as <% ruby code %>, <%= string output %>, or <%- ruby code (with whitespace trimmed) -%>. The equals ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required