Advertisement
overmand

class UsersController < ApplicationController

Mar 22nd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. class UsersController < ApplicationController
  2.  
  3. skip_before_action :require_login, only: [:index, :new, :create, :activate]
  4. # GET /users
  5. # GET /users.json
  6. def index
  7. @users = User.all
  8.  
  9. respond_to do |format|
  10. format.html # index.html.erb
  11. format.json { render json: @users }
  12. end
  13. end
  14.  
  15. # GET /users/1
  16. # GET /users/1.json
  17. def show
  18. @user = User.find(params[:id])
  19.  
  20. respond_to do |format|
  21. format.html # show.html.erb
  22. format.json { render json: @user }
  23. end
  24. end
  25.  
  26. # GET /users/new
  27. # GET /users/new.json
  28. def new
  29. @user = User.new
  30.  
  31. respond_to do |format|
  32. format.html # new.html.erb
  33. format.json { render json: @user }
  34. end
  35. end
  36.  
  37. # GET /users/1/edit
  38. def edit
  39. @user = User.find(params[:id])
  40. end
  41.  
  42. # POST /users
  43. # POST /users.json
  44. def create
  45. @user = User.new(params[:user])
  46.  
  47. respond_to do |format|
  48. if @user.save
  49. format.html { render action: "thanks", notice: 'User was successfully created.' }
  50. format.json { render json: @user, status: :created, location: @user }
  51. else
  52. format.html { render action: "new" }
  53. format.json { render json: @user.errors, status: :unprocessable_entity }
  54. end
  55. end
  56. end
  57.  
  58. # PUT /users/1
  59. # PUT /users/1.json
  60. def update
  61. @user = User.find(params[:id])
  62.  
  63. respond_to do |format|
  64. if @user.update_attributes(params[:user])
  65. format.html { redirect_to @user, notice: 'User was successfully updated.' }
  66. format.json { head :no_content }
  67. else
  68. format.html { render action: "edit" }
  69. format.json { render json: @user.errors, status: :unprocessable_entity }
  70. end
  71. end
  72. end
  73.  
  74. # DELETE /users/1
  75. # DELETE /users/1.json
  76. def destroy
  77. @user = User.find(params[:id])
  78. @user.destroy
  79.  
  80. respond_to do |format|
  81. format.html { redirect_to users_url }
  82. format.json { head :no_content }
  83. end
  84. end
  85. def user_params
  86. params.require(:user).permit(:email, :password, :password_confirmation)
  87. end
  88. def activate
  89. if (@user = User.load_from_activation_token(params[:id]))
  90. @user.activate!
  91. redirect_to(login_path, :notice => 'User was successfully activated.')
  92. else
  93. not_authenticated
  94. end
  95. end
  96. def thanks
  97. respond_to do |format|
  98. format.html # thanks.html.erb
  99. format.json { render json: @user }
  100. end
  101. end
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement