# /app/models/transaction.rb classTransaction < ApplicationRecord # Creates scope for all supported column types TypeScopes.inject self
# Or if you prefer to enable scopes for specific columns only TypeScopes.inject self, :amount, :paid_at end
In case there is a conflict with a scope name, TypeScopes won’t over write your existing scope. You can safely inject TypeScopes and it won’t break any scope defined previously.
For the string colums, the pattern matching is escaped. So it’s safe to provide directly a user input. There is an exception for the column_like, column_ilike, column_matches and column_does_not_match where the pattern is not escaped and you shouldn’t provide untrusted strings.
1
Transaction.description_contains("%foo_") # => where("description LIKE '%[%]foo[_]%'")