Best Programming Practices

CMS Fiona features internal link management that ensures, for example, that CMS file references remain intact when files are renamed or moved. The Rails Connector, however, is not supplied with information about changed file paths. For this reason, you should avoid using calls such as Obj.find(1234) or Obj.find_by_path("/company/news/") in your Rails application.

To be, nevertheless, able to access specific CMS files directly, the Rails Connector offers so-called named links. In the CMS, create a file named NamedLink, based on the NamedLink file format, and give it a related_links link list field. You can now maintain your file references using this link list (the links contained in link lists are covered by link management). In the Rails application, you can then access the linked files by means of the titles that have been given to the links (e.g. NamedLink.get_object("news")). Furthermore, the named link are held in the cache, which saves resources when they are accessed.

Typical use cases for named links are, for example:

  • Display all the CMS files contained in the news folder on your home page:
    NamedLink.get_object("news").each do ...
  • Perform specific actions for a specific page:
    if @obj == NamedLink.get_object("homepage") ...
  • Fetch a field value from a specific file:

Further information about this can be found in the API documentation on the NamedLink class.

Please take account of the following when using named links:

Only one file with the NamedLink format should exist in the CMS because all NamedLink files except the first one are ignored. To prevent editors from creating further files based on the NamedLink format, the format should be deactivated after the file has been created.

Furthermore, the CMS files to which the named links point must be neither deactivated nor unreleased. If the Rails application tries to access a deactivated or unreleased CMS file via a named link, an exception is thrown. If this exception is not explicitly caught it causes all the pages containing this named link to be broken. Depending on where named links pointing to nonexistent targets are used, the complete website might fail.

Adapting a Rails Project to the Local Development Environment

A Rails project can be configured by means of the files config/environment.rb, config/environments/*.rb, and config/initializers/rails_connector.rb.

Starting at version 6.7.3, these configuration files are overridden by Ruby files located in the config/local directory. This makes it possible to adapt the Rails Connector to the local development environment without having to change the project configuration.

By means of these files the Rails configuration as well as the Rails Connector configuration can be adapted locally. An example:

config.action_mailer.delivery_method = :my_local_delivery_method
RailsConnector::Configuration.instance_name = "my_local_instance_name"

Immediately after the Rails Connector has been installed, config/local/configuration.rb is empty, meaning that no changes to the project configuration are made.

If the development of your Rails application is supported by a version control system, it should be configured so as to ignore the files located in the config/local directory.