Adding a LIKE criteria to a Rails Conditions block

activerecord, ruby, ruby-on-rails

Solution

You can scope your model with hash conditions, and then perform `find` on scope with array conditions:

YourModel.scoped(:conditions => conditions).all(:conditions => ["profile like ?", profile])

Problem

Consider the following code which is to be thrown at an AR find: ``` conditions = [] conditions[:age] = params[:age] if params[:age].present? conditions[:gender] = params[:gender] if params[:gender].present? ``` I need to add another condition which is a LIKE criteria on a 'profile' attribute. How can I do this, as obviously a LIKE is usually done via an array, not a hash key.

Original source