Rails gem rails3-jquery-autocomplete: How do I query multiple fields

后端 未结 6 1610
借酒劲吻你
借酒劲吻你 2020-12-03 11:18

I\'m using the rails3-jquery-autocomplete gem found here: http://github.com/crowdint/rails3-jquery-autocomplete

The instructions are clear for how to qu

6条回答
  •  Happy的楠姐
    2020-12-03 11:56

    To perform a case-insensitive search using @Cyril's method for rails4-autocomplete, I did a slight modification to the named scope @DGM provided

     scope :search_by_name, lambda { |q|
       q.downcase!
       (q ? where(["lower(first_name) LIKE ? or lower(last_name) LIKE ? or concat(lower(first_name), ' ', lower(last_name)) like ?", '%'+ q + '%', '%'+ q + '%','%'+ q + '%' ])  : {})
     }
    

    This converts the record's entry to lowercase and also converts the search string to lowercase as it does the comparison

提交回复
热议问题