From 0ebf918d837ad31eb2c91a256a8e1c2eac4e7ab7 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sun, 14 Dec 2014 12:19:52 +0100 Subject: [PATCH] fixed this thing. --- app/models/inbox.rb | 2 +- app/models/question.rb | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/models/inbox.rb b/app/models/inbox.rb index 06c9a2eb..5c664c4a 100644 --- a/app/models/inbox.rb +++ b/app/models/inbox.rb @@ -13,7 +13,7 @@ class Inbox < ActiveRecord::Base end def remove - self.question.destroy if self.question.can_be_removed + self.question.destroy if self.question.can_be_removed? self.destroy end end diff --git a/app/models/question.rb b/app/models/question.rb index 48e6c596..0408a02b 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -4,12 +4,10 @@ class Question < ActiveRecord::Base validates :content, length: { maximum: 255 } - class << self - def can_be_removed - return false if self.answers.count > 0 - return false if Inbox.where(question: self).count > 0 - self.user.decrement! :asked_count - true - end + def can_be_removed? + return false if self.answers.count > 0 + return false if Inbox.where(question: self).count > 1 + self.user.decrement! :asked_count + true end end