๐ SQL Way
User.where('age > ?' age)
๐ ORM Way
User.where(User.arel_table[:age].gt(age))
You can also use these methods.
- = (equal) : eq
- < (less than) : lt
- <= (less than equal) : lteq
- > (greater than) : gt
- >= (greater than equal) : gteq
Tips
User.where(User.arel_table[:name].matches("%#{name_likely}%"))
๐ Gem Way
I hear that the gem named "Squeel" is very useful for this case.
User.where{age > target_age}
Top comments (1)
Squeel does not seem to be actively maintained.
However, Sequel is another ActiveRecord alternative that gives you that block syntax and is actively maintained.
Sequel is powerful and after using it for the past two years, I think I prefer it to ActiveRecord.
It really makes it hard to do dumb stuff like N+1 queries on accident, but I think it takes a lot longer to understand than ActiveRecord.