diff options
-rw-r--r-- | Gemfile.lock | 5 | ||||
-rw-r--r-- | app/models/invite_code.rb | 12 |
2 files changed, 9 insertions, 8 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index 5ffb0c8..3c9a211 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -92,7 +92,6 @@ GEM actionpack (~> 3.0) couchrest couchrest_model - coupon_code (0.0.1) cucumber (1.3.17) builder (>= 2.1.2) diff-lcs (>= 1.1.3) @@ -277,7 +276,6 @@ DEPENDENCIES couchrest (~> 1.1.3) couchrest_model (~> 2.0.0) couchrest_session_store (= 0.3.0) - coupon_code cucumber-rails debugger factory_girl_rails @@ -307,3 +305,6 @@ DEPENDENCIES thin uglifier (~> 1.2.7) valid_email + +BUNDLED WITH + 1.10.6 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 |