Skip to content

Instantly share code, notes, and snippets.

@pablomarti
Created February 13, 2019 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablomarti/947a1b0554ac71bd270e78d19872fed9 to your computer and use it in GitHub Desktop.
Save pablomarti/947a1b0554ac71bd270e78d19872fed9 to your computer and use it in GitHub Desktop.
Modifying Rails validator on runtime
unique_email_validator = validators_on(:email).find { |v|
v.is_a?(ActiveRecord::Validations::UniquenessValidator)
}
def unique_email_validator.validate(*users)
return false if users.map(&:chatbox).all?
return false unless app_users?(users.collect(&:email))
super
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment