Class: ApplicationController
Constant Summary
ControllerCallbacks::METHODS
Instance Attribute Summary
#params, #req, #res
Instance Method Summary
collapse
#form_authenticity_token, #initialize, #invoke_action, #link_to, protect_from_forgery, #root_url
#before_action
Constructor Details
This class inherits a constructor from ControllerBase
Instance Method Details
#current_user ⇒ Object
5
6
7
|
# File 'lib/scaffold/app/controllers/application_controller.rb', line 5
def current_user
@current_user ||= User.find_by(session_token: session[:session_token])
end
|
#ensure_login ⇒ Object
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/scaffold/app/controllers/application_controller.rb', line 9
def ensure_login
unless logged_in?
flash[:errors] = ['must be logged in']
redirect_to new_sessions_url
true
else
false
end
end
|
#ensure_logout ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/scaffold/app/controllers/application_controller.rb', line 20
def ensure_logout
if logged_in?
flash[:errors] = ['already logged in']
redirect_to bands_url
true
else
false
end
end
|
#logged_in? ⇒ Boolean
42
43
44
|
# File 'lib/scaffold/app/controllers/application_controller.rb', line 42
def logged_in?
!!current_user
end
|
#login(user) ⇒ Object
31
32
33
34
|
# File 'lib/scaffold/app/controllers/application_controller.rb', line 31
def login(user)
@current_user = user
session[:session_token] = user.reset_token!
end
|
#logout ⇒ Object
36
37
38
39
40
|
# File 'lib/scaffold/app/controllers/application_controller.rb', line 36
def logout
current_user.reset_token!
session[:session_token] = nil
@current_user = nil
end
|