From a7791635aa98f012d35f97c3c5288494bbb28e38 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 13 Mar 2024 18:03:43 +0100 Subject: Initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- app/controllers/application_controller.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 app/controllers/application_controller.rb (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..2a63b66 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class ApplicationController < ActionController::Base + before_action :user_authenticated! + before_action :set_searches + + helper_method :current_user + + def current_user + @current_user ||= User.find(session[:user_id]) if session[:user_id] + end + + def user_authenticated! + return if current_user + + redirect_to new_sessions_path + end + + def set_searches + @searches = Search.all + end +end -- cgit v1.2.3