2014-11-06 14:46:59 +01:00
|
|
|
class User < ActiveRecord::Base
|
2014-11-09 22:53:39 +01:00
|
|
|
has_many :orders, dependent: :destroy
|
2014-11-06 18:30:53 +01:00
|
|
|
after_initialize :init
|
|
|
|
|
|
|
|
validates :name, presence: true, length: { maximum: 50 },
|
|
|
|
uniqueness: true
|
|
|
|
|
|
|
|
def init
|
|
|
|
self.marks ||= 0
|
|
|
|
self.role ||= "user"
|
2014-11-10 15:52:54 +01:00
|
|
|
end
|
2014-11-06 18:30:53 +01:00
|
|
|
|
2014-11-10 02:30:42 +01:00
|
|
|
def feed
|
|
|
|
# This is preliminary. See "Following users" for the full implementation.
|
|
|
|
Order.where("user_id = ?", id)
|
|
|
|
end
|
2014-11-06 18:30:53 +01:00
|
|
|
|
2014-11-06 14:46:59 +01:00
|
|
|
end
|