blob: 55b7a7453100c986e16f56abbe2c542cccd3a905 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
class InviteCodeValidator < ActiveModel::Validator
def validate(user)
if not_existent?(user.invite_code)
add_error_to_user("This is not a valid code", user)
end
end
private
def not_existent?(code)
InviteCode.find_by__id(code) == nil
end
def add_error_to_user(error, user)
user.errors[:invite_code] << error
end
end
|