Sha256: 4922ac1ac5db6f689ce49efe88572fa6a2bca688010f44954f8a306e61164411

Contents?: true

Size: 1.84 KB

Versions: 12

Compression:

Stored size: 1.84 KB

Contents

=begin
  Camaleon CMS is a content management system
  Copyright (C) 2015 by Owen Peredo Diaz
  Email: owenperedo@gmail.com
  This program is free software: you can redistribute it and/or modify   it under the terms of the GNU Affero General Public License as  published by the Free Software Foundation, either version 3 of the  License, or (at your option) any later version.
  This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the  GNU Affero General Public License (GPLv3) for more details.
=end
class PostComment < ActiveRecord::Base
  include Metas
  self.table_name = "comments"
  attr_accessible :user_id, :post_id, :content, :author, :author_email, :author_url, :author_IP,
                  :approved, :agent, :agent, :typee, :comment_parent

  #default_scope order('comments.created_at ASC')
  #approved: approved | pending | spam

  has_many :metas, ->{ where(object_class: 'PostComment')}, :class_name => "Meta", foreign_key: :objectid, dependent: :destroy
  has_many :children, class_name: "PostComment", foreign_key: :comment_parent, dependent: :destroy
  belongs_to :post, class_name: "Post", foreign_key: :post_id
  belongs_to :parent, class_name: "PostComment", foreign_key: :comment_parent
  belongs_to :user, class_name: "User", foreign_key: :user_id

  default_scope {order('comments.created_at DESC')}

  scope :main, -> { where(:comment_parent => nil) }
  scope :comment_parent, -> { where(:comment_parent => 'is not null') }
  scope :approveds, -> { where(:approved => 'approved') }

  validates :content, :presence => true

  # return the owner of this comment
  def comment_user
    self.user
  end

  # check if this comments is already approved
  def is_approved?
    self.approved == 'approved'
  end

  private

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
camaleon_cms-0.2.1 app/models/post_comment.rb
camaleon_cms-0.2.0 app/models/post_comment.rb
camaleon_cms-0.1.9 app/models/post_comment.rb
camaleon_cms-0.1.8 app/models/post_comment.rb
camaleon_cms-0.1.7 app/models/post_comment.rb
camaleon_cms-0.1.6 app/models/post_comment.rb
camaleon_cms-0.1.5 app/models/post_comment.rb
camaleon_cms-0.1.4 app/models/post_comment.rb
camaleon_cms-0.1.3 app/models/post_comment.rb
camaleon_cms-0.1.2 app/models/post_comment.rb
camaleon_cms-0.0.2 app/models/post_comment.rb
camaleon_cms-0.0.1 app/models/post_comment.rb