31 lines
694 B
Ruby
31 lines
694 B
Ruby
# == Schema Information
|
|
#
|
|
# Table name: users
|
|
#
|
|
# id :integer not null, primary key
|
|
# name :string(255)
|
|
# last_name :string(255)
|
|
# balance :integer default(0)
|
|
# nickname :string(255)
|
|
# password_digest :string(255)
|
|
# created_at :datetime
|
|
# updated_at :datetime
|
|
#
|
|
|
|
class User < ActiveRecord::Base
|
|
has_many :orders, -> { includes :products }
|
|
|
|
validates :name, presence: true
|
|
validates :last_name, presence: true
|
|
validates :nickname, presence: true, uniqueness: true
|
|
|
|
def full_name
|
|
"#{name} #{last_name}"
|
|
end
|
|
|
|
def pay(amount)
|
|
self.increment!(:balance, - amount)
|
|
end
|
|
|
|
has_secure_password
|
|
end
|