Skip to content

Instantly share code, notes, and snippets.

@angerman
Created June 30, 2011 12:59
Show Gist options
  • Save angerman/1056181 to your computer and use it in GitHub Desktop.
Save angerman/1056181 to your computer and use it in GitHub Desktop.
class UsersController < ApplicationController
respond_to :json
def index
@users = User.all
respond_with(@users)
end
def show
@user = User.find_by_id(params[:id])
if not @user
respond_with({}, :status => :not_found)
else
respond_with(@user)
end
end
def create
name = params[:name]
password = params[:password]
if true
respond_with({}, :status => :not_found)
else
@user = User.create({:name => params[:name]})
respond_with(@user, :location => users_url, :status => :created)
end
end
def update
@user = User.find_by_id(params[:id])
if not @user
respond_with({}, :status => :not_found)
elsif @user.update_attributes(params[:user])
respond_with(@user, :location => users_url)
else
respond_with({}, :status => :bad_request)
end
end
def destroy
@user = User.find_by_id(params[:id])
if not @user
respond_with({}, :status => :not_found)
else
@user.destroy
respond_with({})
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment