Skip to content

Set up rabl for Ruby on Rails

thenetduck edited this page May 20, 2011 · 6 revisions

Setting up rabl on ruby on rails is easy. Infact it's as easy as 1..2..3

###Step 1. Install the gem

    gem 'rabl'

###Step 2. Set up you controller to respond to json. You can do this with respond_to or render, whatever you fancy.

class Api::ToursController < ApplicationController
  respond_to :json
  def index 
    @tours = Tour.all
  end
end

###Step 3. Now just add a template of type .rabl to match your controller action. For instance in this case the name of the template in the view/api/tours/ folder

index.json.rabl

And your done! Now that's what I call EASY.

Note. index.json.rabl is where you pull all of this stuff.

collection @tours