fork download
  1. #--------------------------Client Model ------------------------------
  2. class Client < ActiveRecord::Base
  3. has_many :accounts
  4.  
  5. validates :name, :surname, length: { minimum: 2} #walidatory imienia, nazwiska
  6. validates :email, format: { with: /\A.+@.+\z/}
  7. validates :phone, format: { with: /\A\d{3}-\d{3}-\d{3}\z/}
  8.  
  9. def to_s
  10. "#{name} #{surname} (#{id})"
  11. end
  12. end
  13.  
  14. #---------------------------Account Model---------------------------------
  15. class Account < ActiveRecord::Base
  16. belongs_to :client
  17. validates :balance, numericality: { only_integer: true }
  18.  
  19. before_create :set_number
  20.  
  21. def to_s
  22. "[#{number}] #{balance} $"
  23. end
  24.  
  25. protected
  26. def set_number
  27. self.number = rand 1_000_000_000
  28. end
  29. end
  30.  
Runtime error #stdin #stdout #stderr 0.01s 7460KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.rb:2:in `<main>': uninitialized constant ActiveRecord (NameError)