Class: Thredded::Messageboard

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/thredded/messageboard.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.friendly_find!(slug_or_id) ⇒ Thredded::Messageboard

Finds the messageboard by its slug or ID, or raises Thredded::Errors::MessageboardNotFound.

Parameters:

  • slug_or_id (String)

Returns:

Raises:



91
92
93
94
95
# File 'app/models/thredded/messageboard.rb', line 91

def self.friendly_find!(slug_or_id)
  friendly.find(slug_or_id)
rescue ActiveRecord::RecordNotFound
  raise Thredded::Errors::MessageboardNotFound
end

Instance Method Details

#ensure_positionObject



27
28
29
# File 'app/models/thredded/messageboard.rb', line 27

def ensure_position
  self.position ||= (created_at || Time.zone.now).to_i
end

#last_userObject



97
98
99
# File 'app/models/thredded/messageboard.rb', line 97

def last_user
  last_topic.try(:last_user)
end

#normalize_friendly_id(input) ⇒ Object



107
108
109
# File 'app/models/thredded/messageboard.rb', line 107

def normalize_friendly_id(input)
  Thredded.slugifier.call(input.to_s)
end

#update_last_topic!Object



101
102
103
104
105
# File 'app/models/thredded/messageboard.rb', line 101

def update_last_topic!
  return if destroyed?
  self.last_topic = topics.order_recently_posted_first.moderation_state_visible_to_all.first
  save! if last_topic_id_changed?
end