class Comment < ApplicationRecord
extend Enumerize
belongs_to :blog
has_many :replies, class_name: "Comment", foreign_key: "reply_to_id"
belongs_to :reply_to, class_name: "Comment", optional: true
validates :body, presence: true
validates :username, presence: true
validates :email, presence: true, format: URI::MailTo::EMAIL_REGEXP
scope :published_and_ordered, -> { where(status: :published).order(published_at: :asc) }
enumerize :status,
in: [:published, :pending, :rejected],
default: :published,
predicates: true
before_save :set_published_at
def gravatar_url
hash = Digest::MD5.hexdigest(email)
"https://www.gravatar.com/avatar/#{hash}?size=40&default=identicon&rating=g"
end
private
def set_published_at
if self.published?
if self.published_at.blank?
self.published_at = DateTime.now
end
else
self.published_at = nil
end
end
end
a564bfc9bcf422d04c9016f56d65260b007c67'>this commit
blob: f93c8994645d9824d1f4c4a35a708e65a3bfa650 (
plain) (
blame)
1
2
3
4
5
6
|
name: "G Room"
panel_display_name: "Courtyard"
letters {
key: "g"
path: "Components/Collectables/g"
}
|