You probably need to bracket the or statements.
... :conditions => [ ''(title LIKE :search_query OR body LIKE
:search_query) AND end_date >= :now'', ...
-Jonathan.
On 6/25/06, Jasbur <jasbur@gmail.com> wrote:> 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" %>
>
> <h3>Search</h3>
> <b>Keywords: </b>
> <input type=text name="query">
> <b>Location: </b>
> <input type=text name="query_location">
> <input type="submit" value="Search
»" class="primary" />
>
> <%= 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?
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>