2016-12-10 14:01:34 +08:00
|
|
|
|
class User < ActiveRecord::Base
|
|
|
|
|
has_and_belongs_to_many :projects
|
|
|
|
|
has_and_belongs_to_many :missions
|
|
|
|
|
|
|
|
|
|
has_many :notes
|
2016-12-11 15:56:58 +08:00
|
|
|
|
|
|
|
|
|
has_secure_password # 等价于验证password_confirm和password是否相等,并且验证password是否存在
|
|
|
|
|
|
2016-12-11 17:40:47 +08:00
|
|
|
|
validates :name, presence: true, uniqueness: true, length: { maximum: 30 }
|
2016-12-11 15:56:58 +08:00
|
|
|
|
validates :email, presence: true, uniqueness: true, length: { maximum: 50},
|
|
|
|
|
format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
|
2016-12-28 13:34:43 +08:00
|
|
|
|
validates :password, length: { minimum: 6 },on:create
|
2016-12-26 10:44:14 +08:00
|
|
|
|
validates :phone, presence: true, uniqueness: true, format: { with: /\A[0-9]{11,11}\Z/i },
|
|
|
|
|
multiline: false
|
2016-12-10 14:01:34 +08:00
|
|
|
|
end
|