Ruby

Use Contentstack to power content for your Ruby projects

Create Ruby-/RoR- based applications and use the Ruby SDK to fetch and deliver content from Contentstack. The SDK uses Content Delivery APIs.

Getting Started

This guide will help you get started with our Ruby SDK to build apps powered by Contentstack.

SDK Installation and Setup

To use the Ruby SDK, download it using the gem install command:

$ gem install contentstack

Let's get started with the implementation.

Initialize SDK

You will need to specify the API key, Delivery token, and Environment Name of your stack to initialize the SDK:

@stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")

Once you have initialized the SDK, you can start getting content in your app.

Basic Queries

Get a Single Entry

To get a single entry, you need to specify the content type as well as the uid of the entry:

entry = @stack.content_type('content_type_uid').entry("entry_uid").fetch()
puts entry.get('title') # Use `get` method to retrieve field value by providing a field's unique ID

Get Multiple Entries

To retrieve multiple entries of a content type, you need to specify the content type UID. You can also specify search parameters to filter results:

@query = @stack.content_type('blog').query
@entries = @query.where('title', 'welcome')
                 .include_schema
                 .include_count
                 .fetch
puts "Total Entries -- #{@entries.count}"
@entries.each{|entry| puts "#{entry.get('title')}" }

To retrieve localized versions of entries, you can use the query attribute:

entry = @stack.content_type('content_type_uid').query.locale('locale_code').fetch()

Note: Currently, the above query works in case of retrieving localized versions of multiple entries only.

These were example of some of the basic queries of the SDK. For advanced queries, refer to our API reference documentation by visiting the link given below.

API Reference

Go through our SDK API Reference guide to know about the methods that can be used to query your content in Contentstack.

Read Ruby SDK API Reference Guide

Example Apps

To help you get started, we have created a sample application that is powered by Contentstack Ruby SDK. Click on the link below to read the tutorial of the app, view app demo, or download the code from GitHub.

Ruby Demo App

Contentstack provides Ruby SDK using which you can create applications based on Ruby, or any other web frameworks created using Ruby.

Was this article helpful?
top-arrow