Add validations and hooks to User model
This commit is contained in:
parent
12a98d4abd
commit
cb499a68ac
1 changed files with 34 additions and 0 deletions
|
|
@ -1,2 +1,36 @@
|
|||
class User < ApplicationRecord
|
||||
before_save { self.email = email.downcase }
|
||||
|
||||
##### ActiveRecord Validations
|
||||
validates :username,
|
||||
presence: true,
|
||||
length: { minimum: 3, maximum: 26 }
|
||||
|
||||
validates :email,
|
||||
case_sensitive: false,
|
||||
presence: true,
|
||||
uniqueness: true,
|
||||
email: true
|
||||
|
||||
validates :password,
|
||||
length: { minimum: 8 },
|
||||
presence: true,
|
||||
on: :create
|
||||
|
||||
validates :password,
|
||||
length: { minimum: 8 },
|
||||
on: :update,
|
||||
if: :password_digest_changed?
|
||||
|
||||
validates :password_confirmation,
|
||||
presence: true,
|
||||
on: :create
|
||||
|
||||
validates :password_confirmation,
|
||||
presence: true,
|
||||
on: :update,
|
||||
if: :password_digest_changed?
|
||||
|
||||
##### ActiveModel Security
|
||||
has_secure_password
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue