Class: ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/application_controller.rb

Overview

Base class for all application controllers

Defines methods for loading settings and user authentication.

Instance Method Summary collapse

Instance Method Details

#authenticate_user!Object

A before_action to require user login


29
30
31
# File 'app/controllers/application_controller.rb', line 29

def authenticate_user!
  redirect_to  unless current_user
end

#current_userObject

Returns the currently logged in user or nil


21
22
23
24
25
# File 'app/controllers/application_controller.rb', line 21

def current_user
  return unless session[:user_id]

  @current_user ||= User.find(session[:user_id])
end

#load_settingsObject

Load site settings and top level pages


15
16
17
18
# File 'app/controllers/application_controller.rb', line 15

def load_settings
  @settings = Setting.first_or_create
  @top_level_pages = Page.top_level
end