Skip to content

Instantly share code, notes, and snippets.

@AMHOL
Last active October 30, 2015 00:06
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 AMHOL/fdf0a90292914ad758ec to your computer and use it in GitHub Desktop.
Save AMHOL/fdf0a90292914ad758ec to your computer and use it in GitHub Desktop.
class UserValidator
include Dry::Validation
rules << {
title: {
inclusion: %w(Mr Mrs Miss Ms Dr)
},
first_name: {
presence: true
},
last_name: {
presence: true
},
username: {
email: true
}
}
end
class RegistrationValidator < UserValidator
rules << {
username: {
rescues: {
exception: PG::UniqueViolation,
as: :unique
}
},
password: {
length: 8..40
}
}
end
RegistrationValidator.new(params).transaction do
rescue Dry::Validation::Error => e
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment