Complete the code to find all users with the name 'Alice'.
User.where(name: [1])In Rails, to query by a string value, you need to pass the string in quotes. Here, "Alice" is correct.
Complete the code to find all orders with status 'completed'.
Order.where(status: [1])The status value is a string, so it must be quoted. "completed" is correct.
Fix the error in the code to find products with price greater than 100.
Product.where("price [1] ?", 100)
The condition should check for prices greater than 100, so the operator '>' is correct.
Fill both blanks to find users created after 2020-01-01 and with active status true.
User.where("created_at [1] ? AND active = [2]", Date.new(2020,1,1), true)
The query finds users created after a date, so '>' is correct. Active status true means 'true'.
Fill all three blanks to find posts with title containing 'Rails', published before 2023-01-01, and views greater than 1000.
Post.where("title LIKE ? AND published_at [1] ? AND views [2] ?", [3], Date.new(2023,1,1), 1000)
Title uses LIKE with '%Rails%' to find containing text. Published before date uses '<'. Views greater than 1000 uses '>'.
