add user cant follow himself validation

This commit is contained in:
João Victor Geonizeli
2022-02-27 16:23:25 -03:00
parent 70e25e8399
commit 53c7d35d74
3 changed files with 26 additions and 1 deletions

View File

@@ -1,4 +1,12 @@
class UserFollow < ApplicationRecord
belongs_to :follower, class_name: 'User'
belongs_to :followed, class_name: 'User'
validate :followed, :user_cant_follow_himself
private
def user_cant_follow_himself
errors.add(:followed, 'can\'t follow himself') if follower_id == followed_id
end
end