Arel to the rescue
Let’s say you can clean up some queries. Use AREL’s magic by utilizing Rails’ arel_table method.
scope :ids_greater_than_five, -> {
where(arel_table[:id].gt(5))
}
Or snipe queries without scopes!
per = Period.arel_table
Period.where(
per[:id].gt(5).or(per[:id].eq(1))
)
Do not forget: Scopes can make your code cleaner and easier to maintain.
⬅️ Read previous Read next ➡️