2014-12-04 19:50:02 +01:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: users
|
|
|
|
#
|
2014-12-09 18:56:56 +01:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# name :string(255)
|
|
|
|
# last_name :string(255)
|
|
|
|
# balance :integer default(0)
|
|
|
|
# nickname :string(255)
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
# encrypted_password :string(255) default(""), not null
|
|
|
|
# remember_created_at :datetime
|
|
|
|
# sign_in_count :integer default(0), not null
|
|
|
|
# current_sign_in_at :datetime
|
|
|
|
# last_sign_in_at :datetime
|
|
|
|
# current_sign_in_ip :string(255)
|
|
|
|
# last_sign_in_ip :string(255)
|
2014-12-04 19:50:02 +01:00
|
|
|
#
|
|
|
|
|
2014-11-06 14:46:59 +01:00
|
|
|
class User < ActiveRecord::Base
|
2014-12-09 17:17:11 +01:00
|
|
|
devise :database_authenticatable, :registerable,
|
2014-12-09 18:56:56 +01:00
|
|
|
:rememberable, :trackable
|
2014-12-09 17:17:11 +01:00
|
|
|
|
2014-12-06 17:51:41 +01:00
|
|
|
has_many :orders, -> { includes :products }
|
2014-11-06 18:30:53 +01:00
|
|
|
|
2014-12-09 18:56:56 +01:00
|
|
|
validates :nickname, presence: true, uniqueness: true
|
2014-11-25 11:30:55 +01:00
|
|
|
validates :name, presence: true
|
|
|
|
validates :last_name, presence: true
|
2014-12-09 18:56:56 +01:00
|
|
|
validates :password, length: { in: 8..128 }, confirmation: true
|
2014-11-06 18:30:53 +01:00
|
|
|
|
2014-11-25 11:30:55 +01:00
|
|
|
def full_name
|
|
|
|
"#{name} #{last_name}"
|
2014-11-10 02:30:42 +01:00
|
|
|
end
|
2014-11-06 18:30:53 +01:00
|
|
|
|
2014-12-09 10:57:38 +01:00
|
|
|
def pay(amount)
|
|
|
|
self.increment!(:balance, - amount)
|
|
|
|
end
|
2014-11-06 14:46:59 +01:00
|
|
|
end
|