summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorankonym <ankonym@gmail.com>2015-08-21 17:49:36 +0200
committerankonym <ankonym@gmail.com>2015-09-28 15:12:45 +0200
commit0543217b433a8f4809f08018c1a11c20119fa85d (patch)
tree2479c25010afcd5b9b8929979d8b0efb39f4087f /app
parent35494972411d4649ed8e81e24b6ec3f8734f5529 (diff)
assign random invite code when creating new invite codes
Diffstat (limited to 'app')
-rw-r--r--app/models/invite_code.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb
index 751b28e..d52436f 100644
--- a/app/models/invite_code.rb
+++ b/app/models/invite_code.rb
@@ -1,10 +1,19 @@
+require 'coupon_code'
+
class InviteCode < CouchRest::Model::Base
use_database 'invite_codes'
- property :invite_code, String
+ property :invite_code, String, :read_only => true
timestamps!
design do
view :by_invite_code
end
+
+ def initialize(attributes = {}, options = {})
+ super(attributes, options)
+ write_attribute('invite_code', CouponCode.generate) if new?
+ end
+
end
+