Guest User

Untitled

a guest
May 19th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. class UserController < ApplicationController
  2. before_filter :authenticate_user!, :only => [:edit, :update, :destroy]
  3.  
  4. def new
  5. @user = User.new
  6. end
  7.  
  8. def create
  9. @user = User.new(params[:user])
  10.  
  11. if @user.save
  12. if @user.respond_to?(:confirm!)
  13. flash[:notice] = t('devise.confirmations.send_instructions')
  14. sign_in_and_redirect @user if @user.class.confirm_within > 0
  15. else
  16. flash[:notice] = t('flash.users.create.notice', :default => 'User was successfully created.')
  17. redirect_to root_path
  18. end
  19. else
  20. render :new
  21. end
  22. end
  23.  
  24. def edit
  25. @user = current_user
  26. end
  27.  
  28. def update
  29. @user = current_user
  30.  
  31. method = params[:user][:password] ? :update_with_password : :update_attributes
  32. if @user.send(method, params[:user])
  33. flash[:notice] = 'Updated successfully'
  34. redirect_to root_path
  35. else
  36. render :edit
  37. end
  38. end
  39.  
  40. def destroy
  41. current_user.destroy
  42. sign_out current_user
  43. flash[:notice] = t('flash.users.destroy.notice', :default => 'User was successfully destroyed.')
  44. redirect_to root_path
  45. end
  46.  
  47. end
Add Comment
Please, Sign In to add comment