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:



89
90
91
92
93
# File 'app/models/thredded/messageboard.rb', line 89

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



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

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

#last_userObject



95
96
97
# File 'app/models/thredded/messageboard.rb', line 95

def last_user
  last_topic.try(:last_user)
end

#normalize_friendly_id(input) ⇒ Object



105
106
107
# File 'app/models/thredded/messageboard.rb', line 105

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

#update_last_topic!Object



99
100
101
102
103
# File 'app/models/thredded/messageboard.rb', line 99

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