update generation calcuation code, incl. fix user signup bug

This commit is contained in:
Devin Howard 2015-12-15 12:33:22 +08:00
parent b037c84f15
commit b2aa2074a7

View file

@ -7,7 +7,7 @@ class User < ActiveRecord::Base
has_many :maps has_many :maps
has_many :mappings has_many :mappings
before_create :generate_code after_create :generate_code
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable
@ -66,15 +66,10 @@ class User < ActiveRecord::Base
def generate_code def generate_code
self.code = rand(36**8).to_s(36) self.code = rand(36**8).to_s(36)
$codes.push(self.code) $codes.push(self.code)
self.generation = self.get_generation self.generation = get_generation!
end end
def get_generation def get_generation!
calculate_generation() if generation.nil?
generation
end
def calculate_generation
if code == joinedwithcode if code == joinedwithcode
update(generation: 0) update(generation: 0)
else else