Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
programmatic LIKE in Arel
scope :search_uid, ->(*terms) {
where(arel_attribute(:uid).matches_any( {|term| "%#{sanitize_sql_like term}%" }, nil, true))
scope :search, ->(params) {
params.inject(self) do |rel, (key, value)|
value.present? ? rel.where(arel_table[key].matches("%#{sanitize_sql_like(value)}%")) : rel
} 'foo', last_name: 'bar', ...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment