Complete the code to define a scope named active that returns only active users.
scope :active, -> { where(status: [1]) }The scope uses where with the status set to the string "active" to filter active users.
Complete the code to define a scope named recent that returns users created in the last 7 days.
scope :recent, -> { where('created_at >= ?', [1]) }Time.now - 7.days which works but is less idiomatic.Time.current + 7.days.The scope uses 7.days.ago to get the timestamp 7 days before now, filtering recent users.
Fix the error in the scope that filters users by minimum age.
scope :min_age, ->(age) { where('age >= [1]', age) }The SQL query uses a question mark ? as a placeholder for the parameter age.
Fill both blanks to define a scope by_role that filters users by a given role.
scope :by_role, ->(role) { where([1]: [2]) }The scope uses a hash with the key :role and the value from the parameter role to filter users by role.
Fill all three blanks to define a scope search_by_name that finds users with names containing a search term, case-insensitive.
scope :search_by_name, ->(term) { where("LOWER(name) [1] LOWER([2])", [3]) }The scope uses SQL LIKE with LOWER(name) and a pattern built by concatenating '%' before and after the search term to find matching names case-insensitively.