11175
(-- --)
March 31, 2008, 7:26pm
1
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.
11175
(-- --)
March 31, 2008, 7:29pm
2
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
11175
(-- --)
March 31, 2008, 7:36pm
3
Now getting:
can't convert Array into String
app/controllers/pages_controller.rb:13:in `+'
app/controllers/pages_controller.rb:13:in `searchresults'
11175
(-- --)
March 31, 2008, 7:43pm
5
Ah, ok thanks. Got it working now!