Add to your Gemfile:

gem 'buttercms-rails'

Then run:

bundle install

If you don't use bundler:

gem install buttercms-rails

The source is available on Github.

Set your API token in an initializer:

# config/initializers/buttercms.rb
require 'buttercms-ruby'
ButterCMS::api_token = 'your_api_token';

Run this in console:

p ButterCMS::Post.all(page: 1, page_size: 10)

This API request fetches your blog posts. Your account comes with one example post which you'll see in the response.

Next, run:

p ButterCMS::Content.fetch(['homepage_headline']).data

This API request fetches homepage headline content. You can setup your own custom content fields to manage any content kind of content you need.

ButterCMS lets you manage content using our dashboard and integrate it into your tech stack of choice with our content APIs. You can use ButterCMS for new projects as well as add it to existing codebases.

ButterCMS provides a user-friendly UI for managing marketing sites, blogging, and custom content scenarios. We can be used for SEO landing pages, customer case studies, company news & updates, events + webinar pages, education center, location pages, knowledgebases, and more.

We are different from a traditional CMS like Drupal or Wordpress in that we're not a large piece of software you need to download, host, customize, and maintain. Instead we provide easy to consume, performant content API's that you add to your application.

For example, if you wanted to enable a non-technical person to be able to add customer case study pages to your marketing site, you might create a Case Study Page Type to represent these pages. The non-technical person would be able to manage these pages from our dashboard and the JSON API output would look something like this:

{  
  "data": {
    "slug": "acme-co-case-study",
    "fields": {
      "seo_title": "Acme Co Customer Case Study",
      "seo_description": "Acme Co saved 200% on Anvil costs with ButterCMS",
      "title": "Acme Co loves ButterCMS",
      "body": "<p>We've been able to make anvils faster than ever before! - Chief Anvil Maker</p>"
    }
  }
}
Table of Contents

Introduction

Setting up CMS-powered Pages is a simple three-step process:

1) Define the Page Type
2) Create a page
3) Integrate into your application

If you need help after reading this, contact us via email, livechat, or book a time with to pair with one of our developers.

Define Page Type

Create a Page Type to represent your Customer Case Study pages:

Define the fields you want for your customer case studies:

Create Page

With your Page Type defined, you can now create the first case study page. Specify the name and URL of the page...

...then populate the content of the page.

Integration

With your page defined, the ButterCMS API will return it in JSON format like this:

{
    "data": {
        "slug": "acme-co",
        "fields": {
            "facebook_open_graph_title": "Acme Co loves ButterCMS",
            "seo_title": "Acme Co Customer Case Study",
            "headline": "Acme Co saved 200% on Anvil costs with ButterCMS",
            "testimonial": "<p>We've been able to make anvils faster than ever before! - <em>Chief Anvil Maker</em></p>\r\n<p><img src=\"https://cdn.buttercms.com/NiA3IIP3Ssurz5eNJ15a\" alt=\"\" caption=\"false\" width=\"249\" height=\"249\" /></p>",
            "customer_logo": "https://cdn.buttercms.com/c8oSTGcwQDC5I58km5WV",
        }
    }
}

To create these pages in our app, we create a dynamic route that fetches content for the page by using a URL parameter. Here's what the code looks like:

controllers/customers_controller.rb:

class CustomersController < ApplicationController
  def show
    slug = params[:slug]

    @case_study = ButterCMS::Page.get('customer_case_study', slug).data.fields
  end
end

views/customers/show.html.erb:

<html>
  <head>
    <title><%= @case_study.seo_title %></title>
    <meta property="og:title" content="<%= @case_study.facebook_open_graph_title %>" /> 
  </head>
  <body>
    <h1><%= @case_study.headline %></h1>
    <img width="100%" src="<%= @case_study.customer_logo %>">
    <p><%= @case_study.testimonial %></p>
  </body>
</html>

That's it! If you browse to /customers/acme-co, you'll see the Page you created in Butter.

If you need help after reading this, contact us via email, livechat, or book a time with to pair with one of our developers.

Table of Contents

Introduction

Content Fields are global pieces of content that can be managed by your team. They can be used for content that spans multiple pages (header, footer) or platforms (desktop, mobile). Each content field has unique ID for querying via our API. Let's see how you can use them to power a knowledge base. Again Content Fields are great for content that can appear in multiple places so this knowledge base could appear on your website and mobile app. This example will focus on your website.

Two-step process:

  1. Setup custom content fields in Butter
  2. Integrate the fields into your application

If you need help after reading this, contact us via email, livechat, or book a time with to pair with one of our developers.

Setup content fields

Let's suppose we want to add a CMS to a static FAQ page with a title and a list of questions with answers. Here's the initial code for the server and static page:

controllers/pages_controller.rb:

class PagesController < ApplicationController
  def faq
  end
end

views/pages/faq.html.erb:

<h1>FAQ</h1>

<ul>
  <li>
    <h4>When was this company started?</h4>
    <p>2014</p>
  </li>
  <li>
    <h4>What forms of payment do you accept?</h4>
    <p>Credit cards and checks.</p>
  </li>
</ul>

Making your content dynamic with Butter is a two-step process:

  1. Setup custom content fields in Butter
  2. Integrate the fields into your application

To setup custom content fields, first sign in to the Butter dashboard.

Create a new workspace or click on an existing one. Workspaces let you organize content fields in a friendly way for content editors and have no effect on development or the API. For example, a real-estate website might have a workspace called "Properties" and another called "About Page".

Once you're in a workspace click the button to create a new content field. Choose the "Object" type and name the field "FAQ Headline":

After saving, add another field but this time choose the "Collection" type and name the field FAQ Items:

On the next screen setup two properties for items in the collection:

Now go back to your workspace and update your heading and FAQ items.

Integrate your app

To display this dynamic content in our app, we fetch the fields with an API call and then reference them in our view. Here's what the code looks like:

controllers/pages_controller.rb:

class PagesController < ApplicationController
  def faq
    @content = ButterCMS::Content.fetch([:faq_heading, :faq_items]).data
  end
end

views/pages/faq.html.erb:

<h1><%= @content.faq_heading %></h1>

<ul>
  <% @content.faq_items.each do |item| %>
    <li>
      <h4><%= item.question %></h4>
      <p><%= item.answer %></p>
    </li>
  <% end %>
</ul>

That's it! The values entered in the Butter dashboard will immediately update the content in our app.

If you need help after reading this, contact us via email, livechat, or book a time with to pair with one of our developers.

Table of Contents

Introduction

Learn how to quickly build a custom blog with great SEO. If you need help after reading this, contact us via email, livechat, or book a time with to pair with one of our developers.

Using the generator

The Butter Rails gem includes a generator that scaffolds a blog in a single command. Run it using the following command:

rails generate butter:install_blog

The generator creates an initializer file, controllers, and views:

|-- app
    |-- controllers
        |-- buttercms
            |-- authors_controller.rb
            |-- base_controller.rb
            |-- categories_controller.rb
            |-- feeds_controller.rb
            |-- posts_controller.rb
    |-- views
        |-- buttercms
            |-- authors
                |-- show.html.erb
            |-- categories
                |-- show.html.erb
            |-- posts
                |-- _post.html.erb
                |-- index.html.erb
                |-- show.html.erb
        |-- layouts
            |-- buttercms
                |-- default.html.erb

|-- config
    |-- initializers
        |-- buttercms.rb

It also adds routes to your routes.rb file:

scope :module => 'buttercms' do
  get '/categories/:slug' => 'categories#show', :as => :buttercms_category
  get '/author/:slug' => 'authors#show', :as => :buttercms_author

  get '/blog/rss' => 'feeds#rss', :format => 'rss', :as => :buttercms_blog_rss
  get '/blog/atom' => 'feeds#atom', :format => 'atom', :as => :buttercms_blog_atom
  get '/blog/sitemap.xml' => 'feeds#sitemap', :format => 'xml', :as => :buttercms_blog_sitemap

  get '/blog(/page/:page)' => 'posts#index', :defaults => {:page => 1}, :as => :buttercms_blog
  get '/blog/:slug' => 'posts#show', :as => :buttercms_post
end

After running the generator, set your API token in the initializer, restart your server, and browse to http://localhost:3000/blog to view your blog. Your blog includes an index page, post page, category page, and author page as well as RSS, Atom, and sitemap XML feeds.

See our API reference for more information on fetching data:

Comments

Butter doesn't provide an API for comments due to the excellent existing options that integrate easily. Two popular services we recommend are:

Both products are free, include moderation capabilities, and give your audience a familiar commenting experience. They can also provide some additional distribution for your content since users in their networks can see when people comment on your posts. For a minimalist alternative to Disqus, check out RemarkBox or for an open-source option, Isso.

CSS

Butter integrates into your front-end so you have complete control over the design of your blog. The rich text editor allows for formatting that you'll want to make sure you have styled. The boilerplate CSS covers most cases:

.post-container {
  h1, h2, h3, h4, h5 {
    font-weight: 600;
    margin-bottom: 1em;
    margin-top: 1.5em;
  }

  ul, ol {
    margin-bottom: 1.25em;

    li {
      margin-bottom: 0.25em;
    }
  }

  p {
    font-family: Georgia, Cambria, "Times New Roman", Times, serif;
    font-size: 1.25em;
    line-height: 1.58;
    margin-bottom: 1.25em;
    font-weight: 400;
    letter-spacing: -.003em;
  }

  /* Responsive default image width */
  img {
    max-width: 100%;
    height: auto;
  }

  /* Responsive floating */
  @media only screen and (min-width: 720px)  {
    .butter-float-left {
      float: left;
      margin: 0px 10px 10px 0px;
    }

    .butter-float-right {
      float: right;
      margin: 0px 0px 10px 10px;
    }
  }

  /* Image caption */
  figcaption {
    font-style: italic;
    text-align: center;
    color: #ccc;
  }

  /* Inline code highlighting */
  p code {
    padding: 2px 4px;
    font-size: 90%;
    color: #c7254e;
    background-color: #f9f2f4;
    border-radius: 4px;
    font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
  }

  pre {
    display: block;
    padding: 1em;
    margin: 0 0 2em;
    font-size: 1em;
    line-height: 1.4;
    word-break: break-all;
    word-wrap: break-word;
    color: #333333;
    background-color: #f5f5f5;
    font-family: Menlo, Monaco,Consolas, "Courier New", monospace;
  }
}

Migration

To import content from another platform like WordPress or Medium, send us an email.

Get started now

Sign up with Google Sign up with Github
or