Searching in database.

I am new to ROR... I want to search in database using user input.. I am
using sqlite database.
Can anyone guide me?

so far I have done following in model.. I am going in correct way?

Photo_search.rb

def self.search(query)
   if !query.to_s.strip.empty?
   find_by_sql(["select p.* from photos where #{ (["(lower(p.title) like
?
   or lower(p.description) like ?)"] * tokens.size).
   else
      []
   end
end

Please help/suggest.

Rohan Deshpande wrote in post #955103:

Photo_search.rb

def self.search(query)
   if !query.to_s.strip.empty?
   find_by_sql(["select p.* from photos where #{ (["(lower(p.title) like
?
   or lower(p.description) like ?)"] * tokens.size).
   else
      []
   end
end

Try to find a more direct approach to your search features. You should
reserve find_by_sql as an absolute last resort. Rails provides an
extensive and power query language and the Rails community has provided
some really nice gems to help with more complex searches:

It might also be useful for you to try to explain your query in English.
I could take the time to try to figure out what your code is supposed to
do, but my time is valuable. I, as I'm sure others, would appreciate you
take a little of your time to explain what you want instead of simply
throwing the code into your post and making other decipher it. Just a
suggestion, but the more clear your question the better help you will
get from the community.

http://guides.rubyonrails.org/active_record_querying.html
http://github.com/binarylogic/searchlogic

Try to find a more direct approach to your search features. You should
reserve find_by_sql as an absolute last resort. Rails provides an
extensive and power query language and the Rails community has provided
some really nice gems to help with more complex searches:

It might also be useful for you to try to explain your query in
English.
I could take the time to try to figure out what your code is supposed
to
do, but my time is valuable. I, as I'm sure others, would appreciate
you
take a little of your time to explain what you want instead of simply
throwing the code into your post and making other decipher it. Just a
suggestion, but the more clear your question the better help you will
get from the community.

http://guides.rubyonrails.org/active_record_querying.html
http://github.com/binarylogic/searchlogic

I am new to ror.. still learning it.. thanks for your help.. I will
search for the gems available

I am new to ROR.. still learning it.. thanks for ur help.. I will search
for appropriate gems.

Rohan Deshpande wrote in post #955115:

I am new to ROR.. still learning it.. thanks for ur help.. I will search
for appropriate gems.

I hope I was clear that my reply was intended to help and not be a
criticism. I highly recommend that you read through the Rails guides
that I linked earlier. It is well written and gives a great overview of
the Rails 3 query language.

And the rest was intended to help with asking better questions. It's
worth realizing that we follow these posts because we want to help
people that are either new to Rails or are stuck on some particular
problem.

Clear questions tend to get better answers because we (the community)
can spend less time trying to figure out what's being asked.