Ruby on Rails
Monday, November 17, 2014
Then you can simply use
Post.where("name ILIKE %?%", "hello")
or postgres ( can insensitive )
Post.where("name ILIKE %?%", "hello")
On Tue, Nov 18, 2014 at 12:12 PM, Vivek Sampara <ravensnowbird@gmail.com> wrote:
try thisarr = ["XX","YY","AB"," "]def self.custom_search(arr = [])query = []arr.each do |term|query += "title LIKE %#{term}%"endwhere(query.join(" OR "))endIf you're using postgres DBdef self.custom_search(arr = [])query = []arr.each do |term|query += "title ILIKE %#{term}%"endwhere(query.join(" OR "))endPaste this method in any model and call it using like thisPost.custom_search(["XX","YY","AB"," "] )On Mon, Nov 17, 2014 at 10:47 PM, Tal Sh <lists@ruby-forum.com> wrote:Hi guys,
I'm looking for a way to pick up database records by comparing my string
to the database record's string.
The catch is that I have to "clean up" the database strings (not change
the record, just for the purpose of this query).
The basic query is:
Book.where("title = ?","hello")
And I have an array of substrings e.g.
["XX","YY","AB"," "] (the last one is space)
So a record where "hellXX o" or "XX YY hellXX o YY " would be picked
up.
Any ideas? (performance is not important)
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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/72a9ca1464a08150e2fcda643ae7f08b%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAFKVRj8Ds4F5%3D9E_fu0cMf4MM56U-Sz09S7CoTUOsunpotdVNA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment