
Untitled
By: a guest on
May 1st, 2012 | syntax:
None | size: 1.02 KB | hits: 12 | expires: Never
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