Integrating Scrivito into Your Rails Application

Integrating Scrivito into Your Rails Application

Prerequisites

This guide is for integrating Scrivito into a new or existing Rails application. It assumes that you already registered at Scrivito.com, created a trial or paid CMS, and that Ruby, Rails, and the required tools are installed on your machine. See installrails.com, for example, on how to install Ruby and Rails. The instructions refer to Mac OS X, and Ubuntu 14.04 LTS installations. Microsoft Windows is not supported. We recommend using the latest Ruby version. Currently, Scrivito supports Rails 4.2, 5.0 and 5.1.

If you are starting from scratch, please follow the instructions below. Should you already have a furnished Rails application, consider prudently running bundle update prior to integrating Scrivito from step 2.

If you’d rather experiment with a ready-to-use Scrivito-enabled application that comes with several sample pages, widgets, a blog and much more, feel free to download and use the Scrivito Example Application.

1Create your Rails project

(if you have not already)

2Add the gems to your Gemfile

Then execute:

3Remove Turbolinks

As Turbolinks prevents Scrivito from operating properly, please remove references to it in:

  • Gemfile
  • JavaScript assets in app/assets/javascripts/application.js 
  • Application layout in app/views/layouts/application.html.erb (remove the data-turbolinks-track tag attributes)

4Require Scrivito JavaScript assets

Require the jquery and scrivito assets in app/assets/javascripts/application.js after rails-ujs or jquery_ujs.

5Add Scrivito head and body tags

Add scrivito_head_tags to the head section and scrivito_body_tags to the body section in app/views/layouts/application.html.erb.

The result should look like this:

6Specify the Scrivito credentials using environment variables

The values of the keys can be obtained from your Scrivito CMS settings after clicking the CMS instance you would like to use and activating the “Settings” tab. (You only need one set).

If you are comfortable using a bash shell (use echo $SHELL to find out), edit the ~/.bashrc or ~/.zshrc file and add:

Or, we recommend to use the “dotenv-rails” gem and create a .env file in your project, then add the KEY=VALUE pairs to the file.

The Scrivito API keys are your personal keys. Never give them to anyone not involved in developing your Scrivito website! If you use the “.env” mechanism, add this file name to your “.gitignore” file.

7Let Scrivito generate and migrate the basic structures

If you opted to use dotenv-rails, uncomment and update config/initializers/scrivito.rb:

Then execute:

8Start up your Rails app

Start the Rails server with rails server and open http://localhost:3000.

9Optionally integrate a front-end framework

Using the Bootstrap or Foundation framework is simple and fast.

What's next?

Start editing and adding content, or add CMS functionality to your application, e.g. a new page or widget type.