Class: PostComment
Overview
== Schema Information
Table name: post_comments
Database name: primary
id :integer not null, primary key
body :text
email :string(255)
name :string(255)
referrer :string(500)
site_url :string(255)
state :string(20) default("new"), not null
user_agent :string(255)
user_ip :string(255)
created_at :datetime
blogger_id :string(255)
parent_comment_id :integer
post_id :integer
user_id :integer
Indexes
idx_parent_comment_id (parent_comment_id)
idx_post_id_where_pc_is_null (post_id) WHERE (parent_comment_id IS NULL)
idx_state_parent_comment_id (state,parent_comment_id)
index_post_comments_on_post_id_and_created_at (post_id,created_at)
Constant Summary
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary collapse
#creator, #updater
Class Method Summary
collapse
Instance Method Summary
collapse
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
#publish_event
Instance Attribute Details
#body ⇒ Object
41
|
# File 'app/models/post_comment.rb', line 41
validates :body, presence: true
|
#host ⇒ Object
Returns the value of attribute host.
49
50
51
|
# File 'app/models/post_comment.rb', line 49
def host
@host
end
|
Class Method Details
.only_parents ⇒ ActiveRecord::Relation<PostComment>
A relation of PostComments that are only parents. Active Record Scope
46
|
# File 'app/models/post_comment.rb', line 46
scope :only_parents, -> { where(parent_comment_id: nil) }
|
.published ⇒ ActiveRecord::Relation<PostComment>
A relation of PostComments that are published. Active Record Scope
47
|
# File 'app/models/post_comment.rb', line 47
scope :published, -> { where(state: 'published') }
|
.states_for_select ⇒ Object
73
74
75
|
# File 'app/models/post_comment.rb', line 73
def self.states_for_select
state_machines[:state].states.map { |s| [s.human_name.capitalize, s.value] }
end
|
Instance Method Details
36
|
# File 'app/models/post_comment.rb', line 36
belongs_to :article, optional: true
|
#can_publish? ⇒ Boolean
77
78
79
|
# File 'app/models/post_comment.rb', line 77
def can_publish?
.nil? || &.published?
end
|
#child ⇒ Object
115
116
117
|
# File 'app/models/post_comment.rb', line 115
def child
.first
end
|
39
|
# File 'app/models/post_comment.rb', line 39
has_many :child_comments, -> { order(:created_at) }, class_name: 'PostComment', foreign_key: :parent_comment_id
|
81
82
83
|
# File 'app/models/post_comment.rb', line 81
def formatted_created_at
created_at.strftime('%A, %B %e, %Y')
end
|
#make_html_safe ⇒ Object
101
102
103
104
105
106
107
108
109
|
# File 'app/models/post_comment.rb', line 101
def make_html_safe
self.body = sanitize(body).to_s.html_safe
self.site_url = sanitize(site_url).to_s.html_safe if site_url
self.name = sanitize(name).to_s.html_safe if name
self.email = sanitize(email).to_s.html_safe if email
true
end
|
37
|
# File 'app/models/post_comment.rb', line 37
belongs_to :parent_comment, class_name: 'PostComment', optional: true
|
#parsed_body ⇒ Object
85
86
87
|
# File 'app/models/post_comment.rb', line 85
def parsed_body
body
end
|
35
|
# File 'app/models/post_comment.rb', line 35
belongs_to :post, optional: true
|
#request=(request) ⇒ Object
Sets request metadata for tracking purposes
94
95
96
97
98
99
|
# File 'app/models/post_comment.rb', line 94
def request=(request)
self.user_ip = request.remote_ip
self.user_agent = request.env['HTTP_USER_AGENT']
self.referrer = request.env['HTTP_REFERER']
self.host = request.host_with_port
end
|
#send_alert ⇒ Object
111
112
113
|
# File 'app/models/post_comment.rb', line 111
def send_alert
InternalMailer.(self).deliver_later
end
|
#states_for_select ⇒ Object
69
70
71
|
# File 'app/models/post_comment.rb', line 69
def states_for_select
state_transitions.map(&:event).sort
end
|
34
|
# File 'app/models/post_comment.rb', line 34
belongs_to :user, class_name: 'Party', optional: true
|
#user_name ⇒ Object
89
90
91
|
# File 'app/models/post_comment.rb', line 89
def user_name
user ? user.name : name
end
|