diff options
Diffstat (limited to 'app/models/report.rb')
-rw-r--r-- | app/models/report.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/app/models/report.rb b/app/models/report.rb index 6ee562293..36356c48f 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -6,6 +6,7 @@ class Report < ActiveRecord::Base validates :text, presence: true validate :entry_does_not_exist, :on => :create + validate :post_or_comment_does_exist, :on => :create belongs_to :user belongs_to :post @@ -19,6 +20,12 @@ class Report < ActiveRecord::Base end end + def post_or_comment_does_exist + if Post.find_by_id(item_id).nil? && Comment.find_by_id(item_id).nil? + errors[:base] << 'Post or comment was already deleted or doesn\'t exists.' + end + end + def destroy_reported_item if item_type == 'post' delete_post |