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, 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 and 5.0.

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.

1. Create your Rails project

(if you have not already)
$ rails new NAME_OF_YOUR_APPLICATION

2. Add the Scrivito gem to your Gemfile

gem "scrivito", "~> 1.9"

Then execute:

$ bundle install

3. Remove Turbolinks

As Turbolinks conflicts with proper Scrivito operation please remove it's references 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)

4. Require Scrivito JavaScript assets

Require these assets in app/assets/javascripts/application.js after jquery and jquery_ujs.

//= require jquery //= require jquery_ujs //= require scrivito

5. Require Scrivito stylesheet assets

Require these assets in app/assets/stylesheets/application.css.

/* *= require scrivito ... */

6. Add 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:

<html> <head> <title>Scrivito Application</title> … <%= scrivito_head_tags %> … </head> <body> <%= yield %> … <%= scrivito_body_tags %> … </body> </html>

7. Specify the Scrivito credentials using environment variables

The values of the keys can be obtained from your Scrivito Account after clicking the gear icon of the CMS instance you would like to use (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:

export SCRIVITO_TENANT=tenant_id export SCRIVITO_API_KEY=secret

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.

8. Let Scrivito generate and migrate the basic structures

$ rails g scrivito:install

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

  config.tenant = ENV["SCRIVITO_TENANT"]
config.api_key = ENV["SCRIVITO_API_KEY"]

Then execute:

$ bundle exec rake scrivito:migrate scrivito:migrate:publish

9. Start up your Rails app

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

10. Optionally 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.