Skip to content

Instantly share code, notes, and snippets.

@sparkbox
Created August 2, 2011 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sparkbox/1120428 to your computer and use it in GitHub Desktop.
Save sparkbox/1120428 to your computer and use it in GitHub Desktop.
RABL Examples
object @students
attributes :firstname, :lastname, :email, :phonenum
class RablController < ApplicationController
respond_to :json
def index
@students = Student.all
end
end
[
{
"student": {
"firstname": "Drew",
"lastname": "Clemens",
"email": "info@heysparkbox.com",
"phonenum": "937-401-9501"
}
},
{
"student": {
"firstname": "Andy",
"lastname": "Rossi",
"email": "info@heysparkbox.com",
"phonenum": "937-401-9501"
}
}
]
class RailsController < ApplicationController
respond_to :json
def index
@students = Student.all
respond_with(@students) do |format|
format.json { render :json => @students.to_json(:only => [:firstname, :lastname, :email, :phonenum])}
end
end
end
[
{
"email": "info@heysparkbox.com",
"firstname": "Drew",
"lastname": "Clemens",
"phonenum": "937-401-9501"
},
{
"email": "info@heysparkbox.com",
"firstname": "Andy",
"lastname": "Rossi",
"phonenum": "937-401-9501"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment