solution 1: ( I prefer , more easy to understand)
Just write it like raw SQL:
Comment.where(
"(user_id > ? AND user_id < ? ) OR (created_at > ? AND created_at < ?)",
100, 200, "2022-06-01", "2022-06-05")
solution 2:
Comment.
where(:created_at => time_range).
where("user_id is not in (?)",[user_ids])
which will produce SQL like : select ... where ... AND ...