Chapter 8 - Validations Flashcards
Validations
validates_uniqueness_of :username
validates_presence_of :username, :email, :account_number
validates_absence_of :something_unwanted
validates_acceptance_of :privacy_policy, :terms_of_service
validates_acceptance_of :account_cancellation, accept: ‘YES’
validates_confirmation_of :password
= f.label :password_confirmation
= f.password_field
:password_confirmation
validates_format_of :email, 3 with: /\ A([ ^@\ s] +)@((?:[-a-z0-9] +.) +[ a-z]{ 2,})\ z/
validates_inclusion_of :gender, in: %w( m f ), message: ‘O RLY?’
validates_exclusion_of :username, in: %w( admin superuser ),
validates_length_of :login, minimum: 5
validates_length_of :username, within: 5.. 20
Limit Constraint Lookup
validates_uniqueness_of :title,
conditions: -> { where.not(
published_at: nil)
Validates_with
If you want to develop a suite of custom, reusable validation classes.
class EmailValidator