Module: CurrentUser
- Includes:
- CurrentUserId
- Defined in:
- lib/current_user.rb
Instance Method Summary collapse
-
#current_user ⇒ Object
Get the current user: - if it is already set, then return it without doing a lookup - otherwise, find the user via current_user_find(current_user_id).
-
#current_user=(user) ⇒ Object
Set the current user and also set the current user id.
-
#current_user_find(id) ⇒ Object
Return the current user by calling User.find with a user id; if the user id is nil, then return nil for the current user.
Instance Method Details
#current_user ⇒ Object
Get the current user:
- if it is already set, then return it without doing a lookup
- otherwise, find the user via current_user_find(current_user_id)
If the current user is not set, and the current user id is nil, then this returns nil because current_user_find returns nil.
29 30 31 |
# File 'lib/current_user.rb', line 29 def current_user @current_user ||= current_user_find(current_user_id) end |
#current_user=(user) ⇒ Object
Set the current user and also set the current user id.
36 37 38 39 |
# File 'lib/current_user.rb', line 36 def current_user=(user) @current_user = user current_user_id = user ? user.id : nil end |
#current_user_find(id) ⇒ Object
Return the current user by calling User.find with a user id; if the user id is nil, then return nil for the current user.
45 46 47 |
# File 'lib/current_user.rb', line 45 def current_user_find(id) id ? User.find(id,:include=>[:roles]) : nil end |