Retrospring/app/models/report.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

20 lines
485 B
Ruby
Raw Normal View History

2020-04-18 15:59:18 -07:00
class Report < ApplicationRecord
2014-12-27 05:35:09 -08:00
belongs_to :user
2024-01-23 10:57:26 -08:00
belongs_to :target_user, class_name: "User", optional: true
2014-12-27 05:35:09 -08:00
validates :type, presence: true
validates :target_id, presence: true
validates :user_id, presence: true
def target
type.sub('Reports::', '').constantize.where(id: target_id).first
end
2014-12-28 14:26:16 -08:00
2023-01-02 02:16:47 -08:00
def append_reason(new_reason)
if reason.nil?
update(reason: new_reason)
else
update(reason: [reason || "", new_reason].join("\n"))
end
end
2014-12-27 05:35:09 -08:00
end