added forum topic/post

This commit is contained in:
albert
2010-02-20 20:25:01 -05:00
parent 0bb52fd63a
commit 9f05154a5a
11 changed files with 271 additions and 1 deletions

12
app/models/forum_post.rb Normal file
View File

@@ -0,0 +1,12 @@
class ForumPost < ActiveRecord::Base
attr_accessible :body, :topic_id
belongs_to :creator, :class_name => "User"
belongs_to :topic, :class_name => "ForumTopic"
after_save :update_topic_updated_at
validates_presence_of :body, :topic_id, :creator_id
scope :search_body, lambda {|body| where(["text_index @@ plainto_tsquery(?)", body])}
def update_topic_updated_at
topic.touch
end
end

View File

@@ -0,0 +1,7 @@
class ForumTopic < ActiveRecord::Base
attr_accessible :title
belongs_to :creator, :class_name => "User"
has_many :posts, :class_name => "ForumPost", :order => "forum_posts.id asc"
validates_presence_of :title, :creator_id
scope :search_title, lambda {|title| where(["text_index @@ plainto_tsquery(?)", title])}
end