We use a lot of Ruby and Rails at Error Agency, where Rooftop was concieved. So there's a pretty thorough client implementation for both general Ruby (for use with Sinatra, Middleman etc.) and Rails apps.
This tutorial assumes that you're familiar with the structure and function of a pretty standard Rails app. If you're not, dig into that first. We're also assuming you want to see something running. We'll gloss over any magic, and unpack the detail other tutorials.
There's a repo to accompany this guide: https://github.com/rooftopcms/rooftop-rails-demo-app. Each step has a tag.
We'll assume you're familiar enough with Rails to install it and get it running locally.
There are 2 gems you need to add to your Gemfile.
gem 'rooftop' gem 'rooftop-rails'
Don't forget to
bundle after adding them.
The connection to Rooftop is configured in an initializer. There's a Rails generator in the gem to make it easy to add.
There are optional switches to pass in your API token and site name. If you don't add them here, you can edit the initializer later in
rails g rooftop --api-token 7e4a13513520946cc96ce6f4068a1a93 --site-name rooftopdemo
API keys should be secret
You'll notice that if you follow this tutorial, the key will work. We periodically wipe and regenerate this demo site. You should keep your real API keys safe.
For models backed by Rooftop post types, just create normal Ruby classes with the appropriate Rooftop mixin. There are 2 mixins:
Rooftop::Page includes stuff related to pages (including nesting), and
Rooftop::Post includes stuff related to posts.
Here's the code for a Page class:
class Page include Rooftop::Page end
And here's how you create the model for a custom post type - we've called ours 'News Article' in Rooftop:
class NewsArticle include Rooftop::Post end
At this point, you're hooked up to Rooftop and you'll be able to get data using the Rails console.
#return the first page from the demo Rooftop site Page.first #return the first news article from the demo site NewsArticle.first
Updated less than a minute ago