Class: Comment

Inherits:
ApplicationRecord show all
Includes:
PostRelated
Defined in:
app/models/comment.rb

Overview

Represents a comment. Comments are attached to both a post and a user.

Instance Method Summary collapse

Methods inherited from ApplicationRecord

#attributes_print, fuzzy_search, match_search, #match_search, sanitize_for_search, sanitize_name, sanitize_sql_in, useful_err_msg, with_lax_group_rules

Instance Method Details

#content_lengthObject



26
27
28
29
30
31
32
33
# File 'app/models/comment.rb', line 26

def content_length
  stripped = content.strip.tr "\r", ''
  if stripped.size < 15
    errors.add(:content, 'is too short (minimum is 15 characters)')
  elsif stripped.size > 1000
    errors.add(:content, 'is too long (maximum is 1000 characters)')
  end
end

#rootObject



21
22
23
24
# File 'app/models/comment.rb', line 21

def root
  # If parent_question is nil, the comment is already on a question, so we can just return post.
  parent_question || post
end