Sha256: 00622f42357818a1c5ee4aa320ec19ade3f0407b3370d5bfc4f24fcb8f75496b
Contents?: true
Size: 833 Bytes
Versions: 5
Compression:
Stored size: 833 Bytes
Contents
class Comment < ApplicationRecord include Concerns::Parentable include Concerns::Locale include Concerns::Spammable STATUSES = %w(pending_moderation published) after_initialize :default_values belongs_to :commentable, polymorphic: true validates :author, :message, presence: true validates :status, inclusion: { in: STATUSES } validates :email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i } validates :website, url: true, allow_blank: true def published? status.to_s == 'published' end def publish! update_attribute :status, :published end def unpublish! update_attribute :status, :pending_moderation end private def default_values if self.new_record? self.status = 'pending_moderation' if status.nil? end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
udongo-2.0.4 | app/models/comment.rb |
udongo-2.0.3 | app/models/comment.rb |
udongo-2.0.2 | app/models/comment.rb |
udongo-2.0.1 | app/models/comment.rb |
udongo-2.0.0 | app/models/comment.rb |