Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 1.02 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class UsersController < ApplicationController
  2.   respond_to :json
  3.  
  4.   def index
  5.     @users = User.all
  6.     respond_with(@users)
  7.   end
  8.  
  9.   def show
  10.     @user = User.find_by_id(params[:id])
  11.     if not @user
  12.       respond_with({}, :status => :not_found)
  13.     else
  14.       respond_with(@user)
  15.     end
  16.   end
  17.  
  18.   def create
  19.     name = params[:name]
  20.     password = params[:password]
  21.     if true
  22.       respond_with({}, :status => :not_found)
  23.     else
  24.       @user = User.create({:name => params[:name]})
  25.       respond_with(@user, :location => users_url, :status => :created)
  26.     end
  27.   end
  28.  
  29.   def update
  30.     @user = User.find_by_id(params[:id])
  31.     if not @user
  32.       respond_with({}, :status => :not_found)
  33.     elsif @user.update_attributes(params[:user])
  34.       respond_with(@user, :location => users_url)
  35.     else
  36.       respond_with({}, :status => :bad_request)
  37.     end
  38.   end
  39.  
  40.   def destroy
  41.     @user = User.find_by_id(params[:id])
  42.     if not @user
  43.       respond_with({}, :status => :not_found)
  44.     else
  45.       @user.destroy
  46.       respond_with({})
  47.     end
  48.   end
  49. end