summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/invite_code.rb12
1 files changed, 6 insertions, 6 deletions
diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb
index 30d32d6..6fcc427 100644
--- a/app/models/invite_code.rb
+++ b/app/models/invite_code.rb
@@ -14,18 +14,18 @@ class InviteCode < CouchRest::Model::Base
end
def initialize(attributes = {}, options = {})
+ if !attributes.has_key?("_id")
+ attributes[:id] = InviteCode.generate_invite
+ end
+
super(attributes, options)
- write_attribute('invite_code', generate_invite) if new?
+ write_attribute('invite_code', attributes[:id]) if new?
end
- def generate_invite
+ def self.generate_invite
Base64.encode64(SecureRandom.random_bytes).downcase.gsub(/[0oil1+_\/]/,'')[0..7].scan(/..../).join('-')
end
-
- def set_invite_code(code)
- write_attribute(:invite_code, code)
- end
end