Build Contentful-driven Ruby apps with Sinatra and Rails

knowledge-base-white-paper
Published
April 21, 2016
Category

Guides

As we consider Ruby on Rails and Sinatra the most popular Ruby frameworks out there, we assume that many Ruby developers across the world would love to integrate Contentful into their apps in some simple and elegant way.

In this spirit we wrote two demo apps – one for each framework. Each app displays a catalogue of products, quite similar to one you would typically see at an online shop. (The content is coming from our product catalogue template.)

The tutorial for each app explains the thinking behind every step and shows how to use the Contentful Ruby SDK inside a new app – or how to integrate it with your existing applications. We demonstrate several different approaches – the final choice is up to you and depends primarily on the complexity of your project.

Ruby on Rails demo

Using ActiveRecord as the storage abstraction layer for the API and space credentials, we created a customizable
Product Demo. Our SDK Client then uses these credentials and outputs all the content
for the website.

rails product demo

Get the Rails demo app

Sinatra demo

Sinatra doesn't come with built-in database abstractions, so we went for a slightly
different approach, sending the credentials as parameters in the URL. Our routes then handle all the necessary parameters and delegate them to our SDK.

This is all the code that makes it work:

Get the Sinatra demo app

Pull requests are welcome

We'd love to see your ideas, too! Please submit what's on your mind in the shape of PRs or issues.

More tutorials

Feel free to also look at our static site generators examples with
Middleman and
Jekyll.

About the author

Don't miss the latest

Get updates in your inbox
Discover new insights from the Contentful developer community each month.
add-circle arrow-right remove style-two-pin-marker subtract-circle remove