bugfox!
This commit is contained in:
parent
1870acdd3a
commit
82444b8787
|
@ -13,11 +13,7 @@ class Inbox < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove
|
def remove
|
||||||
unless self.question.user.nil?
|
self.question.destroy if self.question.can_be_removed
|
||||||
self.question.user.decrement! :asked_count if self.question.answer_count == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
self.question.destroy if self.question.answer_count == 1
|
|
||||||
self.destroy
|
self.destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,4 +3,13 @@ class Question < ActiveRecord::Base
|
||||||
has_many :answers
|
has_many :answers
|
||||||
|
|
||||||
validates :content, length: { maximum: 255 }
|
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
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue