ensured that new users can sign up with other new users invite codes
This commit is contained in:
parent
a9e488d9cb
commit
2de697bcca
2 changed files with 7 additions and 6 deletions
|
@ -28,12 +28,7 @@ class User < ActiveRecord::Base
|
|||
validates_uniqueness_of :name # done by devise
|
||||
validates_uniqueness_of :email # done by devise
|
||||
|
||||
if ActiveRecord::Base.connection.table_exists? 'users'
|
||||
codes = ActiveRecord::Base.connection.execute("SELECT code FROM users").map {|user| user["code"] }
|
||||
else
|
||||
codes = []
|
||||
end
|
||||
validates :joinedwithcode, :presence => true, :inclusion => { :in => codes, :message => "%{value} is not valid" }, :on => :create
|
||||
validates :joinedwithcode, :presence => true, :inclusion => { :in => $codes, :message => "%{value} is not valid" }, :on => :create
|
||||
|
||||
# This method associates the attribute ":image" with a file attachment
|
||||
has_attached_file :image, :styles => {
|
||||
|
@ -55,6 +50,8 @@ class User < ActiveRecord::Base
|
|||
#generate a random 8 letter/digit code that they can use to invite people
|
||||
self.code = rand(36**8).to_s(36)
|
||||
|
||||
$codes.push(self.code)
|
||||
|
||||
self.generation = self.get_generation
|
||||
end
|
||||
|
||||
|
|
4
config/initializers/access_codes.rb
Normal file
4
config/initializers/access_codes.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
$codes = []
|
||||
if ActiveRecord::Base.connection.table_exists? 'users'
|
||||
$codes = ActiveRecord::Base.connection.execute("SELECT code FROM users").map {|user| user["code"] }
|
||||
end
|
Loading…
Reference in a new issue