This commit is contained in:
r888888888
2013-05-07 17:20:42 -07:00
parent c8f83f1442
commit 72b18051f8
2 changed files with 16 additions and 3 deletions

View File

@@ -7,7 +7,8 @@ class ForumPost < ActiveRecord::Base
before_validation :initialize_creator, :on => :create
before_validation :initialize_updater
before_validation :initialize_is_deleted, :on => :create
after_create :update_topic_updated_at
after_create :update_topic_updated_at_on_create
after_destroy :update_topic_updated_at_on_destroy
validates_presence_of :body, :creator_id
validate :validate_topic_is_unlocked
before_destroy :validate_topic_is_unlocked
@@ -87,7 +88,7 @@ class ForumPost < ActiveRecord::Base
creator_id == user.id || user.is_janitor?
end
def update_topic_updated_at
def update_topic_updated_at_on_create
if topic
topic.updater_id = CurrentUser.id
topic.response_count = topic.response_count + 1
@@ -95,6 +96,10 @@ class ForumPost < ActiveRecord::Base
end
end
def update_topic_updated_at_on_destroy
topic.update_column(:updated_at, ForumPost.where(:topic_id => topic.id).maximum(:updated_at))
end
def initialize_creator
self.creator_id = CurrentUser.id
end