Live Search

    if params['search_text'].strip.length > 0

   terms = params['search_text'].split.collect do |word|
        "^#{word.downcase}"
      end

    b=[];
      terms.to_s.each_byte { |byte| (b.push(byte.chr) if

!b.include?(byte.chr)) if byte.chr.match(/\W+/) }

    b.each do |c|
      terms=terms.to_s.gsub(c) { "\\#{c}"}.to_a
    end


      @users = User.find(
        :all,
        :conditions => [
          ( ["(LOWER(email) RLIKE?)"] * terms.size ).join(" AND "),
          * terms.flatten
          ]
      )

Hi, I’m trying to implemented a live search that only finds data that is
prefixed with the user input (i.e. input=> ‘bo’ -> output => ‘bob’
‘bot’). Furthermore, I need to be able to accept a variable number of
special characters. In the middle of my code I replaced special
characters with ‘’, but I’m not sure how to ESCAPE ‘’ in the SQL at
the end.

Anyway, if there’s a better way to do this, please let me know!!

Thanks!