Question: ok, so probably best if i just paste code and then explain

```
   search = "your horses"

   exp1 = ""
   exp2 = ""

   myarray = search.split(/ /)
   mylength = myarray.length           #this would return 2 in this case

   mylength.times do
    exp1 += "AND name LIKE ? "         #this gives--> AND name LIKE ? AND name LIKE ?
   end

   for i in 0..(mylength - 1)
    exp2 += ("%#{myarray[i]}%, ")    #and this gives--> your, horses,
   end

find(:all, :conditions => ["#{exp1}",  exp2])

```

and here at the end i get a problem because exp2 becomes 'your, horses,' inside the find function. what do i have to do that inside these conditions there would be no additional single quote marks inserted?

or maybe i should do it some other way?

thank you very much for your answers!

Answer: 
```
   search = "your horses"
   myarray = search.split(/ /)
   mylength = myarray.length    
   find(:all, :conditions => [myarray.map{|x| 'name like ?'}.join(' AND '),  *(myarray.map{|x| "%#{x}%"})])

```
I've used a technique of compiling a set of conditions incrementally and then feeding that through to the find call on many occasions an it works especially well for this sort of thing:

```
search = "your horses"

# Establish a template conditions set
conditions = [ [ ] ]

# For each part of the name, add an element
# to the conditions.
search.split(/\s+/).each do |name|
  conditions[0] << 'name LIKE ?'
  conditions << "%#{name}%"
end

# Collapse the array into a single string
conditions[0] = conditions[0].join(' AND ')

# Run the query
find(:all, :conditions => conditions)

```

The key is to start with an empty Array with a single empty Array in it. The WHERE conditions are appended to the first element, and the placeholders are appended to the overall conditions Array.

This is flexible in that you can choose to use OR or AND as required and when augmented with named scopes, can do even more things.