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
|
2014-11-30 09:05:51 -08:00
|
|
|
|
|
|
|
def answer(answer, user)
|
2014-12-12 14:14:32 -08:00
|
|
|
answer = Answer.create!(content: answer,
|
|
|
|
user: user,
|
|
|
|
question: self.question)
|
2014-11-30 09:05:51 -08:00
|
|
|
user.increment! :answered_count
|
2014-12-07 11:51:44 -08:00
|
|
|
self.question.increment! :answer_count
|
2014-11-30 09:05:51 -08:00
|
|
|
self.destroy
|
2014-12-12 14:14:32 -08:00
|
|
|
answer
|
2014-11-30 09:05:51 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove
|
2014-12-14 03:03:57 -08:00
|
|
|
self.question.destroy if self.question.can_be_removed
|
2014-11-30 09:05:51 -08:00
|
|
|
self.destroy
|
|
|
|
end
|
2014-11-10 14:45:36 -08:00
|
|
|
end
|