Class: Thredded::Topic
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Thredded::Topic
show all
- Extended by:
- FriendlyId
- Includes:
- TopicCommon
- Defined in:
- app/models/thredded/topic.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#last_user, #private?, #user
Class Method Details
.find_by_slug_with_user_topic_reads!(slug) ⇒ Object
54
55
56
57
58
|
# File 'app/models/thredded/topic.rb', line 54
def self.find_by_slug_with_user_topic_reads!(slug)
includes(:user_topic_reads).friendly.find(slug)
rescue ActiveRecord::RecordNotFound
raise Thredded::Errors::TopicNotFound
end
|
.inherited(child) ⇒ Object
69
70
71
72
73
74
75
76
77
|
# File 'app/models/thredded/topic.rb', line 69
def self.inherited(child)
child.instance_eval do
def model_name
Topic.model_name
end
end
super
end
|
.order_by_stuck_and_updated_time ⇒ Object
44
45
46
|
# File 'app/models/thredded/topic.rb', line 44
def self.order_by_stuck_and_updated_time
order('thredded_topics.sticky DESC, thredded_topics.updated_at DESC')
end
|
.order_by_updated_time ⇒ Object
40
41
42
|
# File 'app/models/thredded/topic.rb', line 40
def self.order_by_updated_time
order('thredded_topics.updated_at DESC')
end
|
.recent ⇒ Object
84
85
86
|
# File 'app/models/thredded/topic.rb', line 84
def self.recent
limit(10)
end
|
.search(query, messageboard) ⇒ Object
.select_options ⇒ Object
80
81
82
|
# File 'app/models/thredded/topic.rb', line 80
def self.select_options
subclasses.map(&:to_s).sort
end
|
.stuck ⇒ Object
32
33
34
|
# File 'app/models/thredded/topic.rb', line 32
def self.stuck
where(sticky: true)
end
|
.unstuck ⇒ Object
36
37
38
|
# File 'app/models/thredded/topic.rb', line 36
def self.unstuck
where(sticky: false)
end
|
Instance Method Details
#categories_to_sentence ⇒ Object
92
93
94
|
# File 'app/models/thredded/topic.rb', line 92
def categories_to_sentence
categories.map(&:name).to_sentence if categories.any?
end
|
#decorate ⇒ Object
60
61
62
|
# File 'app/models/thredded/topic.rb', line 60
def decorate
TopicDecorator.new(self)
end
|
#public? ⇒ Boolean
64
65
66
|
# File 'app/models/thredded/topic.rb', line 64
def public?
true
end
|
#should_generate_new_friendly_id? ⇒ Boolean
100
101
102
|
# File 'app/models/thredded/topic.rb', line 100
def should_generate_new_friendly_id?
title_changed?
end
|
#updating? ⇒ Boolean
88
89
90
|
# File 'app/models/thredded/topic.rb', line 88
def updating?
id.present?
end
|
#users_to_sentence ⇒ Object
96
97
98
|
# File 'app/models/thredded/topic.rb', line 96
def users_to_sentence
[]
end
|