Complete the code to fetch all users from the database.
users = User.[1]The all method fetches all records from the users table.
Complete the code to find users with the name 'Alice'.
users = User.where(name: [1])In Rails queries, string values must be quoted with single or double quotes. Here, 'Alice' is correct.
Fix the error in the code to get the first user ordered by created_at.
user = User.order(:created_at).[1]The first method returns the first record in the ordered list.
Fill both blanks to get users created after 2023-01-01 and order by name.
users = User.where("created_at > [1]").[2](:name)
sort instead of order.where again instead of order.The date must be a string in quotes. The order method sorts the results by the given column.
Fill all three blanks to select users with age over 30, order by age descending, and limit to 5 results.
users = User.where('age [1] [2]').order(age: [3]).limit(5)
The query filters users older than 30 using '>'. The order is descending with :desc.