Skip to content

Instantly share code, notes, and snippets.

@jackdempsey
Created September 6, 2008 03:48
Show Gist options
  • Save jackdempsey/9084 to your computer and use it in GitHub Desktop.
Save jackdempsey/9084 to your computer and use it in GitHub Desktop.
class Gists < Application
provides :json
def index
@gists = Gist.all
display @gists
end
def show
@gist = Gist.get(params[:id])
raise NotFound unless @gist
display @gist
end
def create
@gist = Gist.new(params[:gist])
if @gist.save
display @gist, :status => Created
else
raise BadRequest
end
end
def update
@gist = Gist.get(params[:id])
raise NotFound unless @gist
if @gist.update_attributes(params[:gist]) || [email protected]?
display @gist, :status => Accepted
else
raise BadRequest
end
end
def destroy
@gist = Gist.get(params[:id])
raise NotFound unless @gist
if @gist.destroy
raise OK
else
raise BadRequest
end
end
end # Gists
class Exceptions < Application
provides :json
# handle BadRequest exceptions (400)
def bad_request
render ''
end
# handle NotFound exceptions (404)
def not_found
render ''
end
# handle NotAcceptable exceptions (406)
def not_acceptable
render ''
end
# handle OK exceptions (200)
def ok
render ''
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment