retrospring/app/models/inbox.rb

23 lines
673 B
Ruby
Raw Normal View History

2020-04-19 00:59:18 +02:00
class Inbox < ApplicationRecord
2014-11-10 23:45:36 +01:00
belongs_to :user
2014-11-11 07:10:02 +01:00
belongs_to :question
2015-01-03 22:27:14 +01:00
before_create do
raise "User does not want to receive anonymous questions" if self.question.author_is_anonymous and self.question.author_name != 'justask' and !self.user.privacy_allow_anonymous_questions?
2015-01-03 22:27:14 +01:00
end
def answer(answer_content, user)
raise Errors::AnsweringOtherBlockedSelf if question.user.blocking?(user)
raise Errors::AnsweringSelfBlockedOther if user.blocking?(question.user)
answer = user.answer(self.question, answer_content)
self.destroy
2014-12-12 23:14:32 +01:00
answer
end
def remove
2014-12-14 12:19:52 +01:00
self.question.destroy if self.question.can_be_removed?
self.destroy
end
2014-11-10 23:45:36 +01:00
end