SQL query syntax

I need to search a specific column with an OR statement from a form, but
can’t quite seem to figure out how. Right now I have:

@query = request.raw_post || request.query_string
@phrase = @query.sub(/ /,"% OR %")
@posts = Post.find(:all,
:conditions => [ ‘(title LIKE :search_query OR
body LIKE :search_query OR city LIKE :search_query OR state LIKE
:search_query OR category LIKE :search_query) AND end_date >= :enddate’,
{:search_query => ‘%’ + @phrase

  • ‘%’, :enddate => Time.now}],
    :order => ‘end_date’)

Let’s say someone enters “big potato” into the search box. I’d like it
to be formed as: %big% OR %potato% The code actually seems to produce
this line, but as soon as the space is typed in the search field
(substituting “% OR %”) all the results dissapear. Am I formatting the
string wrong?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs