Skip to content

Instantly share code, notes, and snippets.

@fmundaca
Created April 16, 2019 16:56
Show Gist options
  • Save fmundaca/535ab7f4c5ee9ea6c4264e8c6be54924 to your computer and use it in GitHub Desktop.
Save fmundaca/535ab7f4c5ee9ea6c4264e8c6be54924 to your computer and use it in GitHub Desktop.
Ayudame
def validate(record)
if !record.email.match(Account::VALID_EMAIL_REGEX)
record.errors[:email] << malformed_field('email', "Email no válido: #{record.email} ")
elsif record.id.nil? # new user
if Account.find_by(email: record.email).present?
record.errors[:email] << malformed_field('email', "Email duplicado: #{record.email}")
# return false
end
else
if !Account.where('email = ? and identifier != ?', record.email, record.identifier).empty?
record.errors[:email] << malformed_field('username', "Email duplicado: #{email}")
# return false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment