0
0
Ruby on Railsframework~10 mins

Uniqueness 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 uniqueness validation for the username attribute in a Rails model.

Ruby on Rails
validates :username, [1]: true
Drag options to blanks, or click blank then click option'
Auniqueness
Bpresence
Clength
Dnumericality
Attempts:
3 left
💡 Hint
Common Mistakes
Using presence instead of uniqueness will only check if the field is filled.
Using length or numericality does not check uniqueness.
2fill in blank
medium

Complete the code to make the uniqueness validation case insensitive.

Ruby on Rails
validates :email, uniqueness: { [1]: false }
Drag options to blanks, or click blank then click option'
Acase_sensitive
Bcase_insensitive
Cignore_case
Dcase_sensitive_option
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent option like case_insensitive.
Setting case_sensitive to true does not ignore case.
3fill in blank
hard

Fix the error in the uniqueness validation syntax.

Ruby on Rails
validates :nickname, uniqueness: [1]
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
C{ case_sensitive: false }
Dnil
Attempts:
3 left
💡 Hint
Common Mistakes
Passing true or false directly when options are needed.
Passing nil causes an error.
4fill in blank
hard

Fill both blanks to add a uniqueness validation scoped to the :account_id attribute.

Ruby on Rails
validates :email, uniqueness: { [1]: :account_id, [2]: false }
Drag options to blanks, or click blank then click option'
Ascope
Bcase_sensitive
Cunique
Dignore_case
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect option names like unique or ignore_case.
Mixing up the order of options.
5fill in blank
hard

Fill all three blanks to add a uniqueness validation with a custom error message and case insensitivity.

Ruby on Rails
validates :username, uniqueness: { [1]: false, [2]: "[3]" }
Drag options to blanks, or click blank then click option'
Acase_sensitive
Bmessage
Chas already been taken
Dscope
Attempts:
3 left
💡 Hint
Common Mistakes
Using scope instead of message for the error text.
Not setting case_sensitive to false for case insensitivity.