0
0
Ruby on Railsframework~10 mins

Presence validation in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a presence validation for the :name attribute in a Rails model.

Ruby on Rails
validates :name, [1]: true
Drag options to blanks, or click blank then click option'
Anumericality
Blength
Cpresence
Duniqueness
Attempts:
3 left
💡 Hint
Common Mistakes
Using length instead of presence
Using uniqueness which checks for duplicates, not presence
2fill in blank
medium

Complete the code to validate presence of :email with a custom error message.

Ruby on Rails
validates :email, presence: [1]
Drag options to blanks, or click blank then click option'
Afalse
Btrue
Cnil
Doptional
Attempts:
3 left
💡 Hint
Common Mistakes
Using false disables validation
Using nil or optional are not valid options here
3fill in blank
hard

Fix the error in the validation code to correctly validate presence of :title.

Ruby on Rails
validates :title, [1]
Drag options to blanks, or click blank then click option'
Apresence: true
Bpresence true
Cpresence => true
Dpresence = true
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces instead of colon
Using => which is old hash rocket syntax but not preferred here
Using equals sign which is invalid
4fill in blank
hard

Fill both blanks to add presence validation for :username and a custom error message.

Ruby on Rails
validates :username, [1]: true, message: [2]
Drag options to blanks, or click blank then click option'
Apresence
B"can't be blank"
C"must be present"
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using length instead of presence
Not quoting the error message string
5fill in blank
hard

Fill all three blanks to validate presence of :password with allow_nil false and a custom message.

Ruby on Rails
validates :password, [1]: true, [2]: false, message: [3]
Drag options to blanks, or click blank then click option'
Apresence
Ballow_nil
C"can't be empty"
Dallow_blank
Attempts:
3 left
💡 Hint
Common Mistakes
Using allow_blank instead of allow_nil
Not quoting the message string
Setting allow_nil to true which disables presence validation