0
0
Ruby on Railsframework~10 mins

Select and pluck 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 select all users with age greater than 20.

Ruby on Rails
users = User.where("age [1] 20")
Drag options to blanks, or click blank then click option'
A>
B<
C=
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' selects younger users.
Using '=' selects only age 20.
2fill in blank
medium

Complete the code to pluck the names of all users.

Ruby on Rails
names = User.[1](:name)
Drag options to blanks, or click blank then click option'
Aselect
Bpluck
Cwhere
Dorder
Attempts:
3 left
💡 Hint
Common Mistakes
Using select returns full objects, not just values.
Using where filters records but doesn't extract values.
3fill in blank
hard

Fix the error in the code to select users with name 'Alice'.

Ruby on Rails
users = User.where(name: [1])
Drag options to blanks, or click blank then click option'
AAlice
B:Alice
C'Alice'
D"Alice"
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted words causes errors.
Using symbols instead of strings for string values.
4fill in blank
hard

Fill both blanks to select users older than 30 and pluck their emails.

Ruby on Rails
emails = User.where("age [1] 30").[2](:email)
Drag options to blanks, or click blank then click option'
A>
Bpluck
Cselect
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' selects younger users.
Using select returns full objects, not just emails.
5fill in blank
hard

Fill all three blanks to select users with age less than 25, order by name, and pluck their ids.

Ruby on Rails
ids = User.where("age [1] 25").[2](:name).[3](:id)
Drag options to blanks, or click blank then click option'
A<
Border
Cpluck
Dwhere
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operator.
Using where instead of order for sorting.
Using select instead of pluck for extracting ids.