好了,可能是最好的,如果我只是粘貼代碼,然後解釋插入可變進查找條件=> SQL查詢
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])
,並在這裏結束我碰到一個問題,因爲EXP2變成了「你的馬,」在find函數中。在這些條件下我必須做什麼,不會有插入額外的單引號標記?
或者我應該採取其他方式?
非常感謝您的回答!
真誠地再次感謝你 – user235195 2010-01-07 23:20:28