Extending Views

The following instructions are addressed to developers who wish to add a view to an existing Rails application which already displays CMS content by means of the Rails Connector. To do this, the following questions need to be answered.

  • Where and how is the view determined that is to be used?
  • Where and how can a new view be created?
  • How can a view be filled with content?

Where and how is the view determined that is to be used?

Usually, it is not necessary to explicitly specify in a Rails application the view to be used for displaying content. You normally follow the convention by naming the view like the corresponding action of the controller. In accordance with this convention, Rails would expect for the CmsController#index action that a view exists under app/views/cms/index.html.erb and use it.

You can follow this convention as long as all objects are to be displayed with an identical layout. However, typically, objects with different formats (objClass), field contents or paths exist. How these differences function in your web application and whether they affect, for example, how an object is displayed, depends on the individual case.

In cases where the format of an object serves as a criterion for layout selection, you can make use of dedicated controllers for specific CMS file formats provided by the Rails Connector.

Where and how can a new view be created?

If dedicated controllers for specific CMS file formats are used, views must be placed in a directory named like the controller and located below app/views/.

How can a view be filled with content?

In applications using the Rails Connector, the content of views is not conceptually different from the content in usual Rails applications. However, in every view an @obj instance is available that represents the object currently loaded. Depending on the format (objClass) assigned to the object, a particular set of fields can be accessed. The fields available include internal CMS fields such as title, name, path, valid_from, and valid_until as well as custom fields such as abstract or showintoc.

For displaying field values, helpers are available. For details, please refer to the API documentation of the Rails Connector.