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!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---