ambition/app/models/user.rb

16 lines
646 B
Ruby
Raw Normal View History

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
validates :phone, presence: true, uniqueness: true, format: { with: /\A[0-9]{11,11}\Z/i },
multiline: false
end