0
0
Ruby on Railsframework~10 mins

Why query interface abstracts SQL in Ruby on Rails - Test Your Understanding

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

Complete the code to fetch all users from the database using ActiveRecord.

Ruby on Rails
users = User.[1]
Drag options to blanks, or click blank then click option'
Aall
Bselect
Cget
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fetch' or 'get' which are not ActiveRecord methods for fetching all records.
2fill in blank
medium

Complete the code to find users with age greater than 30 using ActiveRecord query interface.

Ruby on Rails
users = User.where("age [1] ?", 30)
Drag options to blanks, or click blank then click option'
A>
B<
C=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '=' which would select wrong users.
3fill in blank
hard

Fix the error in the code to order users by name ascending.

Ruby on Rails
users = User.order(name: [1])
Drag options to blanks, or click blank then click option'
A:desc
Bname
C:asc
Dorder
Attempts:
3 left
💡 Hint
Common Mistakes
Using ':desc' which orders descending.
Passing a string instead of a symbol.
4fill in blank
hard

Fill both blanks to select users with name starting with 'A' and order by age descending.

Ruby on Rails
users = User.where("name [1] ?", 'A%').order('age [2]')
Drag options to blanks, or click blank then click option'
ALIKE
BASC
CDESC
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of 'LIKE' for pattern matching.
Ordering ascending instead of descending.
5fill in blank
hard

Fill all three blanks to create a hash mapping user emails to their names for users older than 25.

Ruby on Rails
result = User.where("age [1] ?", 25).pluck([2], [3]).to_h
Drag options to blanks, or click blank then click option'
A>
B:email
C:name
D:age
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '=' for age filter.
Plucking wrong columns like age instead of email or name.