Simple Search Methode - newbie question.

Dear All,

Can you guide me how can i implement a search function in my simple
Bookmark program. In my Bookmark I have "title" and "url",
"description". What I want to do is "search_by" "title".

many thanks in advance,

regards,
koko

Wouldn't you want to use an OR between the conditions here? Otherwise
you're going to only find stuff where the title, url and description
are all the same. What are the odds of that?

Railscasts has a nice screencast called Simple Search Form

Enjoy!
Bryan

Zach Karpinski wrote:

Wouldn't you want to use an OR between the conditions here? Otherwise
you're going to only find stuff where the title, url and description
are all the same. What are the odds of that?

On Jul 20, 11:36�pm, Rails List <rails-mailing-l...@andreas-s.net>

Yep!. It should be OR

Thankyou very much.

def search
t = params[:search][:query]
@q = Model.find(:all, :conditions=>["title like ? AND url like ? AND
description like ?", t,t,t"])
end

Can you explain me this part again?

description like ?", t,t,t"])

what is the t,t,t " in this code ?

regards,

koko

The variable t was assigned to the value in params[:search][:query].
It just makes the example less terse and easier to type out. The
value in t gets substituted for those ? marks. The ? mark method is
better than putting them directly into the conditions string. This is
because Rails will scrub the value in t to make sure it doesn't
contain any attempts to send malicious SQL directly into your
database. Imagine if you will that I sent my query as this:
"; delete all from models;

You probably want to do a search on a partial match since it is
unlikely the user will exactly type in a title, url or description.
This means you'll need to send MySQL some % signs to indicate
variables. Something like this:

@q = Model.find(:all, :conditions=>["title like ? OR url like ? OR
description like ?", "%#{t}%", "%#{t}%", "%#{t}%"])

The "%#{t}%" tells MySQL to search for matches where a title, url, or
description contains the search term. Without them MySQL will try to
match each field exactly to the submitted query. Again, unlikely that
your users will be providing search terms that match that precisely.

Hi, first of all I AM A TOTAL NEWBIE so any help would be deeply
appreciated. I need to do a search like this one only with exact terms
(no like comparison) , but my real problem is that I need to do it
from Flex 3, and I have no idea how can I modify the controller to do
this and how to configure the HTTPService so ruby understands that I
need it to execute the search def :/, I really need help on this one,
please respond.

Thanks in advance for any help.