mercredi 19 décembre 2018

Rails where LIKE pass dynamic attribute with there values

I have search query and there I need to pass dynamic search attribute and values. Following query I am passing all field but those are not dynamic means Some time only first_name will be in search or some time first_name and last_name or some time first_name with age.

How the best way to pass those attributes and values as per found in search method.

Product.where('first_name like ? OR last_name like ? OR age BETWEEN ? AND ?', params[:first_nm], params[:last_nm], params[:age_start], params[:age_end])

Aucun commentaire:

Enregistrer un commentaire