Sha256: a3b0f3ddc73880413a0f10c6e5e06a69822321ce30275a2ad38abc011067d5ef
Contents?: true
Size: 1023 Bytes
Versions: 9
Compression:
Stored size: 1023 Bytes
Contents
module MongoidForums class Post include Mongoid::Document include Mongoid::Timestamps after_create :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
9 entries across 9 versions & 2 rubygems