Class: MyForum::ApplicationController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- MyForum::ApplicationController
show all
- Defined in:
- app/controllers/my_forum/application_controller.rb
Instance Method Summary
collapse
Instance Method Details
#authenticate_user! ⇒ Object
8
9
10
|
# File 'app/controllers/my_forum/application_controller.rb', line 8
def authenticate_user!
redirect_to admin_signin_path unless current_user
end
|
#current_user ⇒ Object
12
13
14
|
# File 'app/controllers/my_forum/application_controller.rb', line 12
def current_user
return session[:user_id].blank? ? nil : User.where(id: session[:user_id]).first
end
|
#current_user_groups ⇒ Object
27
28
29
30
|
# File 'app/controllers/my_forum/application_controller.rb', line 27
def current_user_groups
return [].push UserGroup::GUEST_GROUP.name unless current_user
current_user.user_groups.map &:name
end
|
#current_user_id ⇒ Object
17
18
19
|
# File 'app/controllers/my_forum/application_controller.rb', line 17
def current_user_id
session[:user_id]
end
|
#forum_time(time) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/controllers/my_forum/application_controller.rb', line 38
def forum_time(time)
local_time = time
if local_time.to_date == Time.now.to_date
return t('my_forum.today', hhmm: local_time.strftime('%H:%M'))
elsif local_time.to_date == (Time.now - 1.day).to_date
return t('my_forum.yesterday', hhmm: local_time.strftime('%H:%M'))
end
local_time.strftime('%Y-%m-%d %H:%M')
end
|
#is_admin? ⇒ Boolean
22
23
24
25
|
# File 'app/controllers/my_forum/application_controller.rb', line 22
def is_admin?
return false unless current_user
current_user.is_admin?
end
|
#new_pm_count ⇒ Object
32
33
34
35
|
# File 'app/controllers/my_forum/application_controller.rb', line 32
def new_pm_count
return unless current_user
PrivateMessage.unread_count_for(current_user)
end
|