users_controller.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. class UsersController < ApplicationController
  2. # GET /users
  3. # GET /users.json
  4. def index
  5. @users = User.all
  6. respond_to do |format|
  7. format.html # index.html.erb
  8. format.json { render json: @users }
  9. end
  10. end
  11. # GET /users/1
  12. # GET /users/1.json
  13. def show
  14. @user = User.find(params[:id])
  15. respond_to do |format|
  16. format.html # show.html.erb
  17. format.json { render json: @user }
  18. end
  19. end
  20. # GET /users/new
  21. # GET /users/new.json
  22. def new
  23. @user = User.new
  24. respond_to do |format|
  25. format.html # new.html.erb
  26. format.json { render json: @user }
  27. end
  28. end
  29. # GET /users/1/edit
  30. def edit
  31. @user = User.find(params[:id])
  32. end
  33. # POST /users
  34. # POST /users.json
  35. def create
  36. @user = User.new(params[:user])
  37. respond_to do |format|
  38. if @user.save
  39. format.html { redirect_to @user, notice: 'User was successfully created.' }
  40. format.json { render json: @user, status: :created, location: @user }
  41. else
  42. format.html { render action: "new" }
  43. format.json { render json: @user.errors, status: :unprocessable_entity }
  44. end
  45. end
  46. end
  47. # PUT /users/1
  48. # PUT /users/1.json
  49. def update
  50. @user = User.find(params[:id])
  51. respond_to do |format|
  52. if @user.update_attributes(params[:user])
  53. format.html { redirect_to @user, notice: 'User was successfully updated.' }
  54. format.json { head :no_content }
  55. else
  56. format.html { render action: "edit" }
  57. format.json { render json: @user.errors, status: :unprocessable_entity }
  58. end
  59. end
  60. end
  61. # DELETE /users/1
  62. # DELETE /users/1.json
  63. def destroy
  64. @user = User.find(params[:id])
  65. @user.destroy
  66. respond_to do |format|
  67. format.html { redirect_to users_url }
  68. format.json { head :no_content }
  69. end
  70. end
  71. end