NOTE: rake db:migrate required. added generation column to users

This commit is contained in:
Connor Turland 2014-11-21 16:50:42 -05:00
parent 0ebc3dbc37
commit a9e488d9cb
7 changed files with 166 additions and 135 deletions

6
LiveSiteUpdatesNotes.txt Normal file
View file

@ -0,0 +1,6 @@
make sure that root individuals have same 'joinedwithcode' as 'code'
User.all.each do |u|
u.generation = u.get_generation
u.save
end

View file

@ -10,6 +10,7 @@ module UsersHelper
user['value'] = u.name
user['profile'] = u.image.url(:square)
user['mapCount'] = u.maps.count
user['generation'] = u.generation
user['created_at'] = u.created_at.strftime("%m/%d/%Y")
user['rtype'] = "mapper"

View file

@ -54,6 +54,22 @@ class User < ActiveRecord::Base
def generate_code
#generate a random 8 letter/digit code that they can use to invite people
self.code = rand(36**8).to_s(36)
self.generation = self.get_generation
end
def get_generation
if self.joinedwithcode == self.code
# if your joinedwithcode equals your code you must be GEN 0
gen = 0
elsif self.generation
# if your generation has already been calculated then just return that value
gen = self.generation
else
# if your generation hasn't been calculated, base it off the
# generation of the person whose code you joined with + 1
gen = User.find_by_code(self.joinedwithcode).get_generation + 1
end
end
def settings

View file

@ -144,7 +144,7 @@
<p>Mapping since: {{created_at}}</p>
</div>
<div class="mapperGeneration">
<p>Generation: 1</p>
<p>Generation: {{generation}}</p>
</div>
<div class="mapCount">
{{mapCount}}

View file

@ -0,0 +1,5 @@
class AddGenerationToUsers < ActiveRecord::Migration
def change
add_column :users, :generation, :integer
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140930013020) do
ActiveRecord::Schema.define(:version => 20141121204712) do
create_table "in_metacode_sets", :force => true do |t|
t.integer "metacode_id"
@ -127,6 +127,7 @@ ActiveRecord::Schema.define(:version => 20140930013020) do
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.integer "generation"
end
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true

View file

@ -5,6 +5,7 @@ user:
email: user@user.com
encrypted_password: $2a$10$psR68SWYNy5ZKQPs9FrFM.HuRMrTXO/YFzv.HaUmdCsQZsQrG1XAW
code: qwertyui
joinedwithcode: qwertyui
admin: false
admin:
@ -12,4 +13,5 @@ admin:
email: admin@admin.com
encrypted_password: $2a$10$psR68SWYNy5ZKQPs9FrFM.HuRMrTXO/YFzv.HaUmdCsQZsQrG1XAW
code: iuytrewq
joinedwithcode: iuytrewq
admin: true