summaryrefslogtreecommitdiff
path: root/app/models/invite_code.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/invite_code.rb')
-rw-r--r--app/models/invite_code.rb11
1 files changed, 5 insertions, 6 deletions
diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb
index 5666a4f..9c6df66 100644
--- a/app/models/invite_code.rb
+++ b/app/models/invite_code.rb
@@ -15,13 +15,12 @@ class InviteCode < CouchRest::Model::Base
end
def initialize(attributes = {}, options = {})
- if !attributes.has_key?("_id")
- attributes[:id] = InviteCode.generate_invite
- end
-
+ attributes[:id] = attributes["invite_code"] || InviteCode.generate_invite
super(attributes, options)
-
- write_attribute('invite_code', attributes[:id]) if new?
+ if new?
+ write_attribute('invite_code', attributes[:id])
+ write_attribute('max_uses', attributes[:max_uses] || 1)
+ end
end
def self.generate_invite