Hi, How can I expand the following conditions: conditions = ["first_name LIKE ?", "%#{@params[:query]}%"] to be able to search in other fields in the same database table? I want to be able to run a query using the same query string, but search multiple columns such as first_name, email, and comments. The SQL would be: SELECT first_name, email, comments FROM contacts WHERE first_name LIKE "string" OR email LIKE "string" OR comments LIKE "string" Thanks, David -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
conditions = ["first_name LIKE ? OR email like ?", "%#{@params[:query]}%", "%#{@params[:query]}%"] etc. Vish On 9/27/06, David Lelong <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi, > > How can I expand the following conditions: > > conditions = ["first_name LIKE ?", "%#{@params[:query]}%"] > > to be able to search in other fields in the same database table? > > I want to be able to run a query using the same query string, but search > multiple columns such as first_name, email, and comments. > > The SQL would be: > > SELECT first_name, email, comments FROM contacts WHERE first_name LIKE > "string" OR email LIKE "string" OR comments LIKE "string" > > Thanks, > > David > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
I''m not having luck with that suggestion. I''m getting the following error: parse error, unexpected $, expecting kEND David -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Check your source. You''ve probably got an unclosed begin end block somewhere (syntax error). The way it should work is this: Model.find(:all, :conditions => [''id = ? OR id = ?'', id1, id2]) (the example in my previous mail should read '':conditions =>'' instead of '':conditions ='') Vish On 9/27/06, David Lelong <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I''m not having luck with that suggestion. I''m getting the following > error: > > parse error, unexpected $, expecting kEND > > David > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---