Chapter 8 - Validations Flashcards

1
Q

Validations

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Limit Constraint Lookup

A

validates_uniqueness_of :title,
conditions: -> { where.not(
published_at: nil)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Validates_with

A

If you want to develop a suite of custom, reusable validation classes.

class EmailValidator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly