Integrating with an existing Ruby project

If you already have a Ruby project that you want to integrate with, then you can simply add the Ruby development kit library as a dependency. Let’s walk through all the steps to get integrated into your project!

1. Create a content repository

A content repository is where you define, edit and publish content.

Create a new repository

Next you'll need to model your content, create your custom types, and publish some documents to your repository.

Now, let's take a look at how to connect this new content with your project.

2. Add the development kit as a dependency

Let's add the Ruby kit as a dependency to your project.

Note: you will need to have both Ruby and RubyGems installed on your computer.

Launch the terminal (command prompt or similar on Windows), point it to your project location and run the following command.

gem install --pre

3. Require the prismic gem

To add the gem as a dependency to your project with Bundler, you can add the following line in your Gemfile.

gem '', require: 'prismic'

4. Get the API and query your content

Now we can query your repository and retrieve the content as shown below.

api = Prismic.api('')
doc = api.query("document.type", "page"))
content = doc.results

If you are using a private repository, then you'll need to include your access token like this.

url = ''
token = 'MC5XUkynrnlvQUFIdVViSElaE--_ve-_ve-_vUUece71r77-9FgXvv73vv73uu73v'
api = Prismic.api(url, token)
doc = api.query("document.type", "page"))
content = doc.results

To learn more about querying the API and explore the many ways to retrieve your content, check out the How to Query the API page.

5. Add the queried content to your templates

Once you've retrieved your content, you can include it in your template using the helper functions in the Ruby development kit. Here's a simple example.

<div class="content">
  <h1><%= @page['page.title'].as_text() %></h1>
  <img src="<%= @page['page.image'].url %>" />
  <%= @page['page.description'].as_html(nil).html_safe %>

You can read more about templating your content in the Templating section of the documentation. There you will find explanations and examples of how to template each content field type.

6. Include the prismic toolbar JS file

In order to take advantage of the in-website preview and edit-button functionality, make sure to add the prismic toolbar javascript file to your project.

In the head of every page, be sure to include the following.

<script src="//"></script>
<script type="text/javascript" src="//"></script>

And your journey begins!

You should have all the tools now to really dig into your Ruby project. We invite you to further explore the docs to learn how to define your Custom Types, query the API, and add your content to your templates.