Implementing search

I am a newbie and have created a small blog-like app. Im have tried to
implement the saerch function following this tutorial:
http://snippets.dzone.com/posts/show/1691

Everything seems to work when the searchphase is empty (it finds the
454 rows) but as soon as I start typing it returns nothing. Here is
the controller:

def live_search

@phrase = request.raw_post || request.query_string
a1 = "%"
a2 = "%"
@searchphrase = a1 + @phrase + a2
@results = Funktioner.find(:all, :conditions => [ "Description

LIKE ?", @searchphrase])

@number_match = @results.length

render(:layout => false)

end

The Description-column is text rich and contains the word ledelse, but
when searched it returns:
‘ledelse=’ not found!

One of the puzzels is where the equal sign comes from. It appears also
in the logging og the mysql queries.

Can you help me - anyone?

What does p @phrase return if you do it prior to the query line
p @phrase
@results = Funktioner.find(:all, :conditions => [ “Description
LIKE ?”, @searchphrase])

Also what about
@searchphrase = “%#{@phrase}%”

arbirk wrote:

I am a newbie and have created a small blog-like app. Im have tried to
implement the saerch function following this tutorial:
http://snippets.dzone.com/posts/show/1691

Everything seems to work when the searchphase is empty (it finds the
454 rows) but as soon as I start typing it returns nothing. Here is
the controller:

def live_search

@phrase = request.raw_post || request.query_string
a1 = "%"
a2 = "%"
@searchphrase = a1 + @phrase + a2
@results = Funktioner.find(:all, :conditions => [ "Description

LIKE ?", @searchphrase])

@number_match = @results.length

render(:layout => false)

end

The Description-column is text rich and contains the word ledelse, but
when searched it returns:
‘ledelse=’ not found!

One of the puzzels is where the equal sign comes from. It appears also
in the logging og the mysql queries.

Can you help me - anyone?

arbirk wrote:

@phrase = request.raw_post || request.query_string

The Description-column is text rich and contains the word ledelse, but
when searched it returns:
‘ledelse=’ not found!

One of the puzzels is where the equal sign comes from. It appears also
in the logging og the mysql queries.

Can you help me - anyone?

I think your problem is that later Prototypes always try to
encode a key=value query string, which doesn’t work with
request.raw_post.

So add the option

:with => ‘phrase’

to your observe_field options, and in your controller have

@phrase = params[:phrase]


We develop, watch us RoR, in numbers too big to ignore.

It worked like a charm!

Thanks to both of you for your quick response

Best, David