Class: PostComment
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- PostComment
- Includes:
- ActionView::Helpers::SanitizeHelper, Models::Auditable
- Defined in:
- app/models/post_comment.rb
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
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #body ⇒ Object readonly
-
#host ⇒ Object
Returns the value of attribute host.
Belongs to collapse
Methods included from Models::Auditable
Has many collapse
Class Method Summary collapse
-
.only_parents ⇒ ActiveRecord::Relation<PostComment>
A relation of PostComments that are only parents.
-
.published ⇒ ActiveRecord::Relation<PostComment>
A relation of PostComments that are published.
- .states_for_select ⇒ Object
Instance Method Summary collapse
- #can_publish? ⇒ Boolean
- #child ⇒ Object
- #formatted_created_at ⇒ Object
- #make_html_safe ⇒ Object
- #parsed_body ⇒ Object
-
#request=(request) ⇒ Object
Sets request metadata for tracking purposes.
- #send_alert ⇒ Object
- #states_for_select ⇒ Object
- #user_name ⇒ Object
Methods included from Models::Auditable
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#body ⇒ Object (readonly)
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
#can_publish? ⇒ Boolean
77 78 79 |
# File 'app/models/post_comment.rb', line 77 def can_publish? parent_comment.nil? || parent_comment&.published? end |
#child ⇒ Object
115 116 117 |
# File 'app/models/post_comment.rb', line 115 def child child_comments.first end |
#child_comments ⇒ ActiveRecord::Relation<PostComment>
39 |
# File 'app/models/post_comment.rb', line 39 has_many :child_comments, -> { order(:created_at) }, class_name: 'PostComment', foreign_key: :parent_comment_id |
#formatted_created_at ⇒ Object
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 # puts "make_html_safe, BEFORE: #{body}" self.body = sanitize(body).to_s.html_safe # puts "make_html_safe, AFTER: #{body}" 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 |
#parent_comment ⇒ PostComment
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 |
#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 SystemMailer.blog_comment(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 |
#user ⇒ Party
35 |
# File 'app/models/post_comment.rb', line 35 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 |