negos_app/app/models/reseaux.rb
2017-09-19 11:33:15 +02:00

40 lines
921 B
Ruby

class Reseaux < ActiveRecord::Base
belongs_to :chef_reseau, :class_name => "Customer"
belongs_to :logo_image_file, :class_name => "ImageFile"
belongs_to :background_image_file, :class_name => "ImageFile"
has_many :reseaux_customers
has_many :customers, :through => :reseaux_customers
has_many :needs, :through => :customers
has_many :offer_reseauxes
has_many :offers, :through => :offer_reseauxes
has_many :thing_conversations, :as => :thing
has_many :conversations, :through => :thing_conversations
acts_as_tree
before_create do
self.generate_token
end
def generate_token
self.token = loop do
token = SecureRandom.hex(3)
token = token.upcase
break token unless Reseaux.exists?(token: token) or token.include?("0") or token.include?("O") or token.include?("1") or token.include?("L") or token.include?("I")
end
end
end