diff options
author | ankonym <ankonym@gmail.com> | 2015-10-02 20:58:29 +0200 |
---|---|---|
committer | ankonym <ankonym@gmail.com> | 2015-10-02 20:58:29 +0200 |
commit | 6f09343e85ab23c4d81f827bbd47a720f3e2cf7b (patch) | |
tree | 0b0cdcdf0646f09a8d17baf9199e993b3151b188 /app | |
parent | 82a33300818dd8f6e06856944fe7c658746efca1 (diff) |
Update rake task to allow generation of multi-use invites
The rake task now takes a second (optional) argument that sets the number of uses per invite code.
If this is omitted, the default number of uses is 1.
(This commit also contains some minor code cleanup that removes some stuff that I'd commented out but not removed.)
Diffstat (limited to 'app')
-rw-r--r-- | app/models/invite_code_validator.rb | 8 |
1 files changed, 1 insertions, 7 deletions
diff --git a/app/models/invite_code_validator.rb b/app/models/invite_code_validator.rb index d52e698..9dfe6fa 100644 --- a/app/models/invite_code_validator.rb +++ b/app/models/invite_code_validator.rb @@ -1,4 +1,5 @@ class InviteCodeValidator < ActiveModel::Validator + def validate(user) user_invite_code = InviteCode.find_by_invite_code user.invite_code @@ -8,9 +9,6 @@ class InviteCodeValidator < ActiveModel::Validator elsif has_no_uses_left?(user_invite_code) add_error_to_user("This code has already been used", user) - - # elsif count_greater_than_zero?(user_invite_code) - # add_error_to_user("This code has already been used", user) end end @@ -23,10 +21,6 @@ class InviteCodeValidator < ActiveModel::Validator code.invite_count >= code.invite_max_uses end - # def count_greater_than_zero?(code) - # code.invite_count > 0 - # end - def add_error_to_user(error, user) user.errors[:invite_code] << error end |