# -*- encoding : utf-8 -*- class ForumTopic < ActiveRecord::Base belongs_to :forum_user attr_accessible :description, :title, :forum_messages_attributes, :category_id has_many :forum_messages accepts_nested_attributes_for :forum_messages validates :title, :presence => true belongs_to :category, :class_name => "ForumCategory" def username if self.forum_user self.forum_user.firstname.to_s+" "+ self.forum_user.name.to_s else "utilisateur supprimé" end end def principal self.forum_messages.order("created_at").first end end