From 5519ef78e2b5206b33792656bd8e92368dfd0763 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 13 Jan 2016 10:18:19 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=96=B0=E9=97=BB=E3=80=81?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E8=AE=A8=E8=AE=BA=E5=8C=BA=E5=8C=BA=E5=88=86?= =?UTF-8?q?project=E5=92=8Ccourse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/message.rb | 4 ++-- app/models/news.rb | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/message.rb b/app/models/message.rb index 1d3ae7681..c43657aa5 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -127,7 +127,7 @@ class Message < ActiveRecord::Base # 发帖精辟更新发帖总数 def add_boards_count - if self.parent_id.nil? + if self.project && self.parent_id.nil? count = self.project.boards_count + 1 self.project.update_attribute(:boards_count, count) end @@ -313,7 +313,7 @@ class Message < ActiveRecord::Base # 删除帖子的时候更新帖子总数, 删除回复的时候总数不减少 def decrease_boards_count - if self.parent_id.nil? + if self.project && self.parent_id.nil? count = self.project.boards_count - 1 self.project.update_attribute(:boards_count, count) end diff --git a/app/models/news.rb b/app/models/news.rb index 807206f40..14e570286 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -169,8 +169,10 @@ class News < ActiveRecord::Base end def decrease_news_count - count = self.project.news_count - 1 - self.project.update_attribute(:news_count, count) + if self.project + count = self.project.news_count - 1 + self.project.update_attribute(:news_count, count) + end end def send_mail