我已經在我的模型下面的搜索用戶輸入的字符串:如何解決這個搜索方法
def self.find_products(product="")
find(:all, :select => 'product_id, name', :order => "name", :conditions => ["name like ? and locale =?", "%#{product.capitalize}%", I18n.locale])
end
但它只能如果字符串是一個詞。 如果字符串包含兩個或更多單詞(如「卡片指南」),則即使這些單詞是名稱中的確切單詞,它也不會返回任何內容。
如何正確執行此搜索。
的Rails的Ruby 3 1.9.2
更新
事實證明,它的一個PostgreSQL語法。我需要使用iLIKE來區分大小寫。然後它運作得更好。我仍然喜歡下面的答案,因爲它也有助於完善我的語法。
謝謝Vivek幫助了很多 – chell