Safe ActiveRecord like query

后端 未结 5 530
别那么骄傲
别那么骄傲 2020-11-30 04:27

I\'m trying to write LIKE query.

I read that pure string quires aren\'t safe, however I couldn\'t find any documentation that explain how to write safe LIKE Hash Que

5条回答
  •  伪装坚强ぢ
    2020-11-30 04:57

    Using Arel you can perform this safe and portable query:

    title = Model.arel_table[:title]
    Model.where(title.matches("%#{query}%"))
    

提交回复
热议问题