This repository has been archived on 2024-08-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
redstoner.com/app/models/forumthread.rb
2014-04-28 03:01:33 +02:00

45 lines
849 B
Ruby

class Forumthread < ActiveRecord::Base
belongs_to :forum
belongs_to :user_author, class_name: "User", foreign_key: "user_author_id"
belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id"
has_many :threadreplies
validates_presence_of :title, :author, :forum
validates_presence_of :content
validates_length_of :content, in: 5..10000
accepts_nested_attributes_for :threadreplies
def to_s
title
end
def author
@author ||= if self.user_author.present?
user_author
else
User.first
end
end
def editor
# can be nil
@editor ||= user_editor
end
def edited?
!!user_editor_id
end
def replies
threadreplies
end
def can_read?(user)
forum.can_read?(user)
end
def can_write?(user)
forum.can_write?(user) && (!locked? || user.mod?)
end
end