IF you really need to search over several columns, use concat() for db 
columns... like

scope :search, labda{|search| where("concat(name, genre, console) like ?", 
"%#{search}%").presence || all }

and then use

Model.search('value')

tom

On Feb 21, 2012, at 16:44 , Roger Patrick wrote:

> I am currently writing a search method for my rails applications and at
> the moment it works fine. I have the following in my game.rb:
> 
> def self.search(search)
> if search
>   find(:all, :conditions => ['name LIKE ? OR genre LIKE ? OR
> console LIKE ?', "%#{search}%", "#{search}", "#{search}"])
> else
>   find(:all)
> end
> end
> 
> Now that searches fine but my problem is that if there is a record in
> game_name that has the words playstation in it will finish the search
> there and only return that record rather than that as well as all games
> that have playstation stored in console. Now I understand that is
> because I have OR in my conditions but I don't know an alternative. AND
> simply requires all the conditions to match or no return at all. What is
> an alternative I can use to AND and OR. Help would be much appreciated.
> 
> If there is a solution that has seperate search boxes and entries then
> that would be fine, I don't necessarily require the search to find it
> all based on one search form.
> 
> -- 
> Posted via http://www.ruby-forum.com/.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to 
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.

-- 
===============================================================================
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

www.meinlschmidt.com  www.maxwellrender.cz  www.lightgems.cz
===============================================================================

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to