Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ApplicationController < ActionController::Base
- before_action :validate_session
- def validate_session
- if session[:user].nil?
- redirect_to new_session_path if controller_name != 'sessions'
- else
- redirect_to home_index_path if controller_name == 'sessions' && action_name != 'destroy'
- end
- end
- end
- class SessionsController < ApplicationController
- def new
- end
- def create
- session[:user] = { usuario: params[:usuario] }
- redirect_to home_index_path
- end
- def destroy
- session.delete(:user)
- redirect_to new_session_path
- end
- end
Add Comment
Please, Sign In to add comment