-
Notifications
You must be signed in to change notification settings - Fork 335
Setup for Sinatra
jewilmeer edited this page Aug 30, 2011
·
13 revisions
Setting up RABL on Sinatra is easy. In fact it's as easy as 1..2..3
###Step 1. Install the gem
$ gem install sinatra
###Step 2.
Set up your sinatra app to support RABL:
# app.rb
require 'rubygems'
require 'sinatra'
require 'rabl'
require 'active_support/core_ext'
require 'active_support/inflector'
require 'builder'
# Register RABL
Rabl.register!
# Render RABL
get "/" do
@foo = # ...
render :rabl, :foo, :format => "json"
end
###Step 3.
Now just add a template of type .rabl to match the template referenced in your route to be rendered. For instance, in this case the name of the template is views/foo.rabl
# views/foo.json.rabl
object @foo
# Declarations here
And your done! Now that's what I call easy.