The Layout of a Rails Application

Rails applications are not based on the layout files stored in the CMS but on views which are an essential part of the Rails application itself. Views are HTML files that contain code with which the content can be dynamically included in the web pages to be displayed.

In a Rails project, a designer creates the layout of the web pages. The layout is based on Rails layout files that contain the HTML framework of the web pages to be delivered, i.e. templates. These templates contain placeholders that the Rails server replaces with content later on. What is inserted into the templates depends on the views used, and the view is determined by the URL the visitor has opened.

The placeholders in the layout include a main section (mostly for displaying the main content) as well as other named sections which are optional. The view supplies the content for all sections. Thus, it also contains a main section as well as the optional named sections. If a layout contains a named section for which no corresponding section exists in the view, the section remains empty in the generated web page.

To create or modify the design, the designer adapts the layout and the views to make them generate pages that meet the design specification. Typically, the layout references style sheets whose classes are used both in the layout and the views. The data for which the view is executed is rendered by means of Ruby code the designer embeds into the layout and the views.

From version 6.7.1, our Rails Connector supports two template languages for writing views and layouts: ERB (Embedded Ruby) and Liquid.

The ERB template language is part of Ruby’s standard library. When using ERB, Ruby code is embedded directly into views and layouts. CMS content within ERB templates can be displayed using the Rails Connector. The file name extension of ERB templates is .html.erb.

Liquid is a template language implemented in Ruby with a focus on security and robustness. Liquid templates have a simple syntax and are therefore simpler to write with less danger of making errors. The Rails Connector expands upon Liquid’s basic syntax in order to facilitate displaying CMS content. The file name extension of Liquid templates is .html.liquid.

In a Rails application, views and layouts can be written interchangeably in Liquid or ERB.