Created
August 2, 2011 15:30
-
-
Save sparkbox/1120428 to your computer and use it in GitHub Desktop.
RABL Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object @students | |
attributes :firstname, :lastname, :email, :phonenum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RablController < ApplicationController | |
respond_to :json | |
def index | |
@students = Student.all | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"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" | |
} | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"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