Query problem with 'LIKE'

Hi. I'm trying to implement a basic search, but the LIKE clause in the query dosen't seem to work as I expected. The result is only found if the exact phrase is typed in to the field.

Have I made some sort of error?

query = params[:title] @results = Auction.find(:all, :conditions => ["title like ?", query])

Any help would be appreciated. Thanks.

query = params[:title] @results = Auction.find(:all, :conditions => ["title like ?", query])

You have to include the '%'

@results = Auction.find(:all, :conditions => ["title like ?", '%' + query + '%'])

that should work.

-S

Now getting:

can't convert Array into String

app/controllers/pages_controller.rb:13:in `+' app/controllers/pages_controller.rb:13:in `searchresults'

Now getting:

can't convert Array into String

app/controllers/pages_controller.rb:13:in `+' app/controllers/pages_controller.rb:13:in `searchresults'

Ah, ok thanks. Got it working now!:slight_smile: