Module: NotificationsHelper

Included in:
Activity
Defined in:
app/helpers/notifications_helper.rb

Instance Method Summary collapse

Instance Method Details

#description_of(act_obj) ⇒ Object

An activity object description



16
17
18
19
20
21
22
# File 'app/helpers/notifications_helper.rb', line 16

def description_of(act_obj)
  if act_obj.respond_to? :description and (not act_obj.description.nil?)
    sanitize(act_obj.description)
  else
    I18n.t('notification.watch_it')
  end
end

#locale_as(subject) ⇒ Object

Set locale as per subject preference



25
26
27
28
29
# File 'app/helpers/notifications_helper.rb', line 25

def locale_as(subject)
  if subject.respond_to? :language
    I18n.locale = subject.language || I18n.default_locale
  end
end

#notification_url_of(target, notification) ⇒ Object

Add notification_id param to URL in order to mark notification read



32
33
34
35
# File 'app/helpers/notifications_helper.rb', line 32

def notification_url_of(target, notification)
  return polymorphic_url(target, :notification_id => notification.id) unless notification.nil?
  polymorphic_url(target)
end

#title_of(act_obj) ⇒ Object

An activity object title



4
5
6
7
8
9
10
11
12
13
# File 'app/helpers/notifications_helper.rb', line 4

def title_of(act_obj)
  if act_obj.is_a? Comment
    'Re: ' + title_of(act_obj.parent_post)
  elsif act_obj.respond_to? :title and (not act_obj.title.nil?)
    act_obj.title.truncate(30, :separator => ' ')
  elsif act_obj.respond_to? :url and (not act_obj.url.nil?)
    act_obj.url.truncate(30, :separator => ' ')
  else I18n.t('notification.default')
  end
end