Skip to content

Instantly share code, notes, and snippets.

@r3cha
Last active May 27, 2020 09:23
Show Gist options
  • Save r3cha/96bbd1bb0e9462251f2b077fcbad81fd to your computer and use it in GitHub Desktop.
Save r3cha/96bbd1bb0e9462251f2b077fcbad81fd to your computer and use it in GitHub Desktop.
Mongoid Rails model concern
# 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