The code powering m.abunchtell.com https://m.abunchtell.com
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

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