From b2aa2074a7ce78e2ff405700324af14f2084fe4f Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 15 Dec 2015 12:33:22 +0800 Subject: [PATCH] update generation calcuation code, incl. fix user signup bug --- app/models/user.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index ce68d61b..fd3f4787 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,7 +7,7 @@ class User < ActiveRecord::Base has_many :maps has_many :mappings - before_create :generate_code + after_create :generate_code devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable @@ -66,15 +66,10 @@ class User < ActiveRecord::Base def generate_code self.code = rand(36**8).to_s(36) $codes.push(self.code) - self.generation = self.get_generation + self.generation = get_generation! end - def get_generation - calculate_generation() if generation.nil? - generation - end - - def calculate_generation + def get_generation! if code == joinedwithcode update(generation: 0) else