Sha256: 59903f760de315d57f000b4fc77d57d8bcfd67d2cdb856d2dc17b5ce0accfa71
Contents?: true
Size: 834 Bytes
Versions: 4
Compression:
Stored size: 834 Bytes
Contents
class Comment < ActiveRecord::Base 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
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
udongo-1.0.4 | app/models/comment.rb |
udongo-1.0.3 | app/models/comment.rb |
udongo-1.0.2 | app/models/comment.rb |
udongo-1.0.1 | app/models/comment.rb |