creddit/app/models/comment.rb

25 lines
460 B
Ruby
Raw Normal View History

2015-12-11 15:26:51 -05:00
# models/comment.rb
2015-07-16 11:57:27 -04:00
class Comment < ActiveRecord::Base
has_ancestry
belongs_to :user
belongs_to :post, counter_cache: true
delegate :username, to: :user, prefix: true
2015-12-11 15:26:51 -05:00
delegate :subcreddit, to: :post, prefix: true
2015-07-16 11:57:27 -04:00
validates :content, presence: true
def content
destroyed? ? '[deleted]' : read_attribute(:content)
end
def destroy
update_attribute(:deleted_at, Time.now)
end
def destroyed?
self.deleted_at != nil
end
end