The code powering m.abunchtell.com https://m.abunchtell.com
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

18 wiersze
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