This commit is contained in:
albert
2013-03-17 20:56:34 -04:00
parent 781bfcef3c
commit 69607c0ea8
4 changed files with 23 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ class ForumPost < ActiveRecord::Base
validates_presence_of :body, :creator_id
validate :validate_topic_is_unlocked
before_destroy :validate_topic_is_unlocked
after_save :delete_topic_if_original_post
module SearchMethods
def body_matches(body)
@@ -122,6 +123,14 @@ class ForumPost < ActiveRecord::Base
ForumPost.exists?(["id = ? and id = (select _.id from forum_posts _ where _.topic_id = ? order by _.id asc limit 1)", id, topic_id])
end
def delete_topic_if_original_post
if is_deleted? && is_original_post?
topic.update_attribute(:is_deleted, true)
end
true
end
def build_response
dup.tap do |x|
x.body = x.quoted_response