Complete the code to fetch all users from the database using ActiveRecord.
users = User.[1]The all method fetches all records from the users table using ActiveRecord's query interface.
Complete the code to find users with age greater than 30 using ActiveRecord query interface.
users = User.where("age [1] ?", 30)
The where method uses SQL conditions. To find users older than 30, use the '>' operator.
Fix the error in the code to order users by name ascending.
users = User.order(name: [1])The order method accepts :asc or :desc symbols to specify ascending or descending order. Use :asc for ascending.
Fill both blanks to select users with name starting with 'A' and order by age descending.
users = User.where("name [1] ?", 'A%').order('age [2]')
Use LIKE to match names starting with 'A'. Use DESC to order age descending.
Fill all three blanks to create a hash mapping user emails to their names for users older than 25.
result = User.where("age [1] ?", 25).pluck([2], [3]).to_h
Use '>' to filter users older than 25. pluck extracts email and name columns. to_h converts array pairs to a hash.