Forum: Ruby on Rails Implementing search

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2d40070e97b1d22d909ef6b1701f0860?d=identicon&s=25 arbirk (Guest)
on 2007-06-25 17:11
(Received via mailing list)
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?
2f5156b0296b508cd92229fcd5d0cf53?d=identicon&s=25 Vincent (Guest)
on 2007-06-25 17:22
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?
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2007-06-25 20:18
(Received via mailing list)
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.
2d40070e97b1d22d909ef6b1701f0860?d=identicon&s=25 arbirk (Guest)
on 2007-06-25 20:51
(Received via mailing list)
It worked like a charm!

Thanks to both of you for your quick response

Best, David
This topic is locked and can not be replied to.