I am new to Rails and I am looking for databases. I have a model and a database that has a list of names under the "name" attribute. I want to be able to enter keywords in one search field, and this input can consist of one word or two words or more, depending on what specific result the user needs.
Right now, I'm using something ugly, as shown below, which will use no more than three search queries. Is there a way to make this dynamic for the keywords "search_length"? The find method is clearly repeated, but I'm not sure how to automate it and have not found any useful suggestions elsewhere on the Internet.
def self.search(search)
if search
search_length = search.split.length
find(:all, :conditions => ['name LIKE ? AND name LIKE ? AND name LIKE ?',
"%#{search.split[0]}%", "%#{search.split[1]}%",
"%#{search.split[search_length1]}%"])
else
find(:all)
end
end
Other than that, loving Rails so far.
,