|
|
Question : Active Record LIKE
|
|
Does Active Record have a method that takes in an Array and searches a table where a certain field is like every element in the Array?
What I want to do is to pass in an Array of strings and do a lookup on a certain field.
["Jones", "James", "Smith"]
SQL should be "select * from people where last_name like 'Jones%' or 'James%' or 'Smith%'"
|
Answer : Active Record LIKE
|
|
You can use find_by_sql: http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000993 Just pass in your SQL and away you go. Of course, depending on how complex your SQL is, it could become database-dependent, which may be a problem or not.
If you want to allow more flexible searches, give acts_as_ferret a try: http://projects.jkraemer.net/acts_as_ferret/wiki
|
|
|
|
|