class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
end

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  helper_method :current_user, :logged_in?

  def current_user
    User.find_by(user_id: session[:user_id])
  end

  def logged_in?
    !current_user.nil?
  end
end

Add the current_user and logged_in? methods to the Application controller.
Add the current_user and logged_in? methods to the Application
controller.

These methods will be available to all controllers that inherit from
Application Controller. They have been declared as helper methods as
well, so that the views can also make use of them.
