Sha256: 479c1b859c021bd8487c6f2711f9ddbc67672c154dffd08ee8ec94a82c500715
Contents?: true
Size: 1022 Bytes
Versions: 4
Compression:
Stored size: 1022 Bytes
Contents
module MongoidForums class Post include Mongoid::Document include Mongoid::Timestamps before_save :set_topic_last_post_at belongs_to :topic, :class_name => "MongoidForums::Topic" belongs_to :user, :class_name => MongoidForums.user_class.to_s belongs_to :reply_to, :class_name => "MongoidForums::Post" has_many :replies, :class_name => "MongoidForums::Post", :foreign_key => "reply_to_id", :dependent => :nullify field :text, type: String validates :text, :presence => true class << self def by_created_at order_by([:created_at, :asc]) end def by_updated_at order_by([:updated_at, :desc]) end end def owner_or_admin?(other_user) user == other_user || (other_user.mongoid_forums_admin? || topic.forum.moderator?(other_user)) end protected def set_topic_last_post_at self.topic.update_attribute(:last_post_at, self.created_at) end end end
Version data entries
4 entries across 4 versions & 1 rubygems