0
0
Ruby on Railsframework~10 mins

Length 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 validate that the username is at least 3 characters long.

Ruby on Rails
validates :username, length: { minimum: [1] }
Drag options to blanks, or click blank then click option'
A10
B5
C3
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using max instead of minimum
Setting the minimum length too high or too low
2fill in blank
medium

Complete the code to validate that the password length is between 6 and 12 characters.

Ruby on Rails
validates :password, length: { in: [1] }
Drag options to blanks, or click blank then click option'
A6..12
B3..8
C5..10
D8..15
Attempts:
3 left
💡 Hint
Common Mistakes
Using a range that is too short or too long
Using an array instead of a range
3fill in blank
hard

Fix the error in the code to validate that the title length is at most 50 characters.

Ruby on Rails
validates :title, length: { [1]: 50 }
Drag options to blanks, or click blank then click option'
Amaximum
Bmax
Cminimum
Dlimit
Attempts:
3 left
💡 Hint
Common Mistakes
Using max instead of maximum
Using limit which is not valid here
4fill in blank
hard

Fill both blanks to validate that the email length is exactly 10 characters.

Ruby on Rails
validates :email, length: { [1]: [2] }
Drag options to blanks, or click blank then click option'
Ais
Bminimum
C10
Dmaximum
Attempts:
3 left
💡 Hint
Common Mistakes
Using minimum or maximum instead of is
Setting the length to a range instead of a single number
5fill in blank
hard

Fill all three blanks to validate that the nickname length is between 4 and 8 characters and allow blank values.

Ruby on Rails
validates :nickname, length: { [1]: [2], [3]: true }
Drag options to blanks, or click blank then click option'
Ain
B4..8
Callow_blank
Dallow_nil
Attempts:
3 left
💡 Hint
Common Mistakes
Using allow_nil instead of allow_blank
Setting length with minimum and maximum keys separately