Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def self.find_with_fuzzy_keywords(attrs={})
  attrs.reject! &:blank?
  attrs[:keywords] = [] || attrs[:keywords].collect { |word| "%#{word}%" }
  
  condition_string = (
    attrs.except(:keywords).collect { |key,value|
      "#{key} = ?"
    } + attrs[:keywords].collect { |key,value|
      "#{key} LIKE ?"
    }
  ).join(" AND ")
  
  find(
    :all,
    :conditions => attrs.collect { |key,value|
      value
    }.unshift(condition_string)
  )
end