Class: PostComment
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- PostComment
- Includes:
- ActionView::Helpers::SanitizeHelper, Models::Auditable, RouteUrlHelpers
- 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 RouteUrlHelpers
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #body ⇒ String 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 ⇒ void
Instance Method Summary collapse
- #can_publish? ⇒ Boolean
- #child ⇒ void
- #formatted_created_at ⇒ void
- #make_html_safe ⇒ void
- #parsed_body ⇒ void
-
#request=(request) ⇒ void
Sets request metadata for tracking purposes.
- #send_alert ⇒ void
- #states_for_select ⇒ void
- #user_name ⇒ void
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 Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#body ⇒ String (readonly)
46 |
# File 'app/models/post_comment.rb', line 46 validates :body, presence: true |
#host ⇒ Object
Returns the value of attribute host.
54 55 56 |
# File 'app/models/post_comment.rb', line 54 def host @host end |
Class Method Details
.only_parents ⇒ ActiveRecord::Relation<PostComment>
A relation of PostComments that are only parents. Active Record Scope
51 |
# File 'app/models/post_comment.rb', line 51 scope :only_parents, -> { where(parent_comment_id: nil) } |
.published ⇒ ActiveRecord::Relation<PostComment>
A relation of PostComments that are published. Active Record Scope
52 |
# File 'app/models/post_comment.rb', line 52 scope :published, -> { where(state: 'published') } |
.states_for_select ⇒ void
This method returns an undefined value.
80 81 82 |
# File 'app/models/post_comment.rb', line 80 def self.states_for_select state_machines[:state].states.map { |s| [s.human_name.capitalize, s.value] } end |
Instance Method Details
#can_publish? ⇒ Boolean
85 86 87 |
# File 'app/models/post_comment.rb', line 85 def can_publish? parent_comment.nil? || parent_comment&.published? end |
#child ⇒ void
This method returns an undefined value.
131 132 133 |
# File 'app/models/post_comment.rb', line 131 def child child_comments.first end |
#child_comments ⇒ ActiveRecord::Relation<PostComment>
43 |
# File 'app/models/post_comment.rb', line 43 has_many :child_comments, -> { order(:created_at) }, class_name: 'PostComment', foreign_key: :parent_comment_id |
#formatted_created_at ⇒ void
This method returns an undefined value.
90 91 92 |
# File 'app/models/post_comment.rb', line 90 def formatted_created_at created_at.strftime('%A, %B %e, %Y') end |
#make_html_safe ⇒ void
This method returns an undefined value.
115 116 117 118 119 120 121 122 123 |
# File 'app/models/post_comment.rb', line 115 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?
40 |
# File 'app/models/post_comment.rb', line 40 belongs_to :parent_comment, class_name: 'PostComment', optional: true |
#parsed_body ⇒ void
This method returns an undefined value.
95 96 97 |
# File 'app/models/post_comment.rb', line 95 def parsed_body body end |
#request=(request) ⇒ void
This method returns an undefined value.
Sets request metadata for tracking purposes
107 108 109 110 111 112 |
# File 'app/models/post_comment.rb', line 107 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 ⇒ void
This method returns an undefined value.
126 127 128 |
# File 'app/models/post_comment.rb', line 126 def send_alert SystemMailer.blog_comment(self).deliver_later end |
#states_for_select ⇒ void
This method returns an undefined value.
75 76 77 |
# File 'app/models/post_comment.rb', line 75 def states_for_select state_transitions.map(&:event).sort end |
#user ⇒ Party?
36 |
# File 'app/models/post_comment.rb', line 36 belongs_to :user, class_name: 'Party', optional: true |
#user_name ⇒ void
This method returns an undefined value.
100 101 102 |
# File 'app/models/post_comment.rb', line 100 def user_name user ? user.name : name end |