Using AND in :conditions queries

I have what amounts to a simple search engine running through a table
using input from a form. Everything works fine when looking for “title”
or “body” But, when I want to couple that with an AND statement the
search still works fine, but it seems to disregard the AND statements.
Code below:

In the view:

<%= start_form_tag :action=> “show_search” %>

Search

Keywords: Location:
<%= end_form_tag %>

and the controller:

@posts = Post.find(:all,
:conditions => [ ‘title LIKE :search_query OR
body LIKE :search_query AND end_date >= :now’,
{:search_query => ‘%’ +
params[:query] + ‘%’, :now => Time.now}],
:order => ‘end_date’)

I did check the log and all the variables are being passed ok. I’m
guessing I’m using the AND statement wrong. Any ideas?

You probably need to bracket the or statements.

… :conditions => [ ‘(title LIKE :search_query OR body LIKE
:search_query) AND end_date >= :now’, …

-Jonathan.