0
0
Ruby on Railsframework~10 mins

Index creation 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 an index on the users table for the email column.

Ruby on Rails
add_index :users, :[1]
Drag options to blanks, or click blank then click option'
Aname
Bage
Cemail
Dcreated_at
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a column that is rarely searched, like created_at.
Forgetting to specify the column name.
2fill in blank
medium

Complete the code to add a unique index on the username column in the users table.

Ruby on Rails
add_index :users, :username, unique: [1]
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
Cnil
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using unique: false which does not enforce uniqueness.
Omitting the unique option.
3fill in blank
hard

Fix the error in the code to add a multi-column index on first_name and last_name.

Ruby on Rails
add_index :users, [1]
Drag options to blanks, or click blank then click option'
A[:first_name, :last_name]
B:first_name, :last_name
Cfirst_name, last_name
D['first_name', 'last_name']
Attempts:
3 left
💡 Hint
Common Mistakes
Passing columns as separate arguments instead of an array.
Using strings instead of symbols.
4fill in blank
hard

Fill both blanks to add an index on the orders table for the user_id column with a custom name.

Ruby on Rails
add_index :orders, :[1], name: '[2]'
Drag options to blanks, or click blank then click option'
Auser_id
Border_user_index
Cuser_index
Dcustomer_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column name like customer_id.
Not providing a meaningful index name.
5fill in blank
hard

Fill all three blanks to add a unique index on the email column of the customers table with a custom name.

Ruby on Rails
add_index :customers, :[1], unique: [2], name: '[3]'
Drag options to blanks, or click blank then click option'
Aemail
Btrue
Cunique_email_index
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Setting unique to false which does not enforce uniqueness.
Using a generic or missing index name.