Guest User

Untitled

a guest
May 21st, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. class ApplicationController < ActionController::Base
  2. before_action :validate_session
  3.  
  4. def validate_session
  5. if session[:user].nil?
  6. redirect_to new_session_path if controller_name != 'sessions'
  7. else
  8. redirect_to home_index_path if controller_name == 'sessions' && action_name != 'destroy'
  9. end
  10. end
  11. end
  12.  
  13. class SessionsController < ApplicationController
  14.  
  15. def new
  16. end
  17.  
  18. def create
  19. session[:user] = { usuario: params[:usuario] }
  20. redirect_to home_index_path
  21. end
  22.  
  23. def destroy
  24. session.delete(:user)
  25. redirect_to new_session_path
  26. end
  27.  
  28. end
Add Comment
Please, Sign In to add comment