The code powering m.abunchtell.com https://m.abunchtell.com
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

18 lignes
579 B

  1. # frozen_string_literal: true
  2. # See also: USERNAME_RE in the Account class
  3. class UniqueUsernameValidator < ActiveModel::Validator
  4. def validate(account)
  5. return if account.username.nil?
  6. normalized_username = account.username.downcase
  7. normalized_domain = account.domain&.downcase
  8. scope = Account.where(Account.arel_table[:username].lower.eq normalized_username).where(Account.arel_table[:domain].lower.eq normalized_domain)
  9. scope = scope.where.not(id: account.id) if account.persisted?
  10. account.errors.add(:username, :taken) if scope.exists?
  11. end
  12. end