Rails 4 LIKE query - ActiveRecord adds quotes

前端 未结 7 1580
轮回少年
轮回少年 2020-12-02 09:07

I am trying to do a like query like so

def self.search(search, page = 1 )
  paginate :per_page => 5, :page =>          


        
7条回答
  •  爱一瞬间的悲伤
    2020-12-02 09:28

    If someone is using column names like "key" or "value", then you still see the same error that your mysql query syntax is bad. This should fix:

    .where("`key` LIKE ?", "%#{key}%")
    

提交回复
热议问题