Retrospring/app/models/inbox.rb

22 lines
502 B
Ruby
Raw Normal View History

2014-11-10 14:45:36 -08:00
class Inbox < ActiveRecord::Base
belongs_to :user
2014-11-10 22:10:02 -08:00
belongs_to :question
def answer(answer, user)
Answer.create(content: answer,
user: user,
question: self.question)
user.increment! :answered_count
self.destroy
end
def remove
unless self.question.user.nil?
2014-12-07 11:13:45 -08:00
self.question.user.decrement! :asked_count if self.question.answers.count == 1
end
2014-12-07 11:13:45 -08:00
self.question.destroy if self.question.answers.count == 1
self.destroy
end
2014-11-10 14:45:36 -08:00
end