Last active
May 27, 2020 09:23
-
-
Save r3cha/96bbd1bb0e9462251f2b077fcbad81fd to your computer and use it in GitHub Desktop.
Mongoid Rails model concern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/models/concerns/user_jwt.rb | |
module UserJwt | |
extend ActiveSupport::Concern | |
included do | |
include ActiveModel::SecurePassword | |
has_secure_password | |
field :email, type: String | |
field :phone, type: String | |
field :first_name, type: String | |
field :last_name, type: String | |
field :password_digest, type: String | |
field :username, type: String | |
validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP } | |
validates :password, length: { minimum: 8 }, if: -> { new_record? || password } | |
def full_name | |
"#{first_name} #{last_name}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment