Class: Forum
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Forum
- Extended by:
- FriendlyId
- Includes:
- DmCore::Concerns::PublicPrivate, RankedModel
- Defined in:
- app/models/forum.rb
Class Method Summary collapse
-
.notify_followers(start_time, end_time = Time.now) ⇒ Object
Send comment notifications to any followers ——————————————————————————.
Instance Method Summary collapse
-
#followed_topics(user) ⇒ Object
——————————————————————————.
-
#normalize_friendly_id(text) ⇒ Object
use babosa gem (to_slug) to allow better handling of multi-language slugs ——————————————————————————.
-
#normalize_slug ⇒ Object
If user set slug sepcifically, we need to make sure it’s been normalized ——————————————————————————.
-
#should_generate_new_friendly_id? ⇒ Boolean
regenerate slug if it’s blank ——————————————————————————.
-
#to_s ⇒ Object
——————————————————————————.
Class Method Details
.notify_followers(start_time, end_time = Time.now) ⇒ Object
Send comment notifications to any followers
63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/forum.rb', line 63 def self.notify_followers(start_time, end_time = Time.now) comments = Comment.where(commentable_type: 'ForumTopic', created_at: start_time..end_time) comments_by_topic = comments.group_by {|i| i.commentable_id } comments_by_topic.each do |topic_id, topic_comments| forum_topic = ForumTopic.find(topic_id) followers = forum_topic.followers followers.each do |follower| email = ForumNotificationMailer.follower_notification(follower.user, forum_topic, topic_comments).deliver_now end end end |
Instance Method Details
#followed_topics(user) ⇒ Object
52 53 54 |
# File 'app/models/forum.rb', line 52 def followed_topics(user) user.following.following_by_type('ForumTopic').where(forum_id: self.id) end |
#normalize_friendly_id(text) ⇒ Object
use babosa gem (to_slug) to allow better handling of multi-language slugs
47 48 49 |
# File 'app/models/forum.rb', line 47 def normalize_friendly_id(text) text.to_s.to_slug.normalize.to_s end |
#normalize_slug ⇒ Object
If user set slug sepcifically, we need to make sure it’s been normalized
35 36 37 |
# File 'app/models/forum.rb', line 35 def normalize_slug self.slug = normalize_friendly_id(self.slug) end |
#should_generate_new_friendly_id? ⇒ Boolean
regenerate slug if it’s blank
41 42 43 |
# File 'app/models/forum.rb', line 41 def should_generate_new_friendly_id? self.slug.blank? end |
#to_s ⇒ Object
57 58 59 |
# File 'app/models/forum.rb', line 57 def to_s name end |