Class: CortexReaver::Comment
- Inherits:
-
Object
- Object
- CortexReaver::Comment
show all
- Includes:
- Model::Renderer
- Defined in:
- lib/cortex_reaver/model/comment.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#bluecloth, #erubis_filter, #macro, #render, #render_comment, #sanitize_html, #syntax_highlight
#attr_h, #errors_list, #errors_on, #form_for, #form_p, #form_submit
#delete_attachment, included
#page_navigation, #page_navigation_helper, #page_select, #subpage_navigation
Class Method Details
.get(id) ⇒ Object
45
46
47
|
# File 'lib/cortex_reaver/model/comment.rb', line 45
def self.get(id)
self[id]
end
|
.recent ⇒ Object
49
50
51
|
# File 'lib/cortex_reaver/model/comment.rb', line 49
def self.recent
reverse_order(:created_on).limit(16)
end
|
.url ⇒ Object
53
54
55
|
# File 'lib/cortex_reaver/model/comment.rb', line 53
def self.url
'/comments'
end
|
Instance Method Details
#after_create ⇒ Object
Increment parent comment count WARNING: If we reparent comments as opposed to just posting, this will break.
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/cortex_reaver/model/comment.rb', line 32
def after_create
super
parent = self.parent
parent. += 1
parent.skip_timestamp_update = true
parent.save
true
end
|
#before_destroy ⇒ Object
Update parent comment counts
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/cortex_reaver/model/comment.rb', line 18
def before_destroy
return false unless super
parent = self.parent
parent. -= 1
parent.skip_timestamp_update = true
parent.save
true
end
|
#to_s ⇒ Object
57
58
59
|
# File 'lib/cortex_reaver/model/comment.rb', line 57
def to_s
'comment ' + id.to_s
end
|
#url ⇒ Object
61
62
63
|
# File 'lib/cortex_reaver/model/comment.rb', line 61
def url
root_parent.url + '#comment_' + id.to_s
end
|
#validate ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/cortex_reaver/model/comment.rb', line 65
def validate
validates_presence :body
validates_max_length 255, :name, :allow_blank => true
validates_max_length 255, :http, :allow_blank => true
validates_max_length 255, :email, :allow_blank => true
validates_format(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/, :email, :allow_blank => true)
if (not email.blank?) and User.filter(:email => email).count > 0
self.errors[:email] << 'conflicts with a registered user'
end
count = 0
[:page_id, :journal_id, :comment_id, :photograph_id].each do |field|
unless self[field].blank?
count += 1
if count > 1
self.errors[:comment] << 'has too many kinds of parents'
break
end
end
end
if count == 0
self.errors[:comment] << "doesn't have a parent"
end
end
|